diff options
Diffstat (limited to 'server/tests/cli')
-rw-r--r-- | server/tests/cli/create-generate-storyboard-job.ts | 120 | ||||
-rw-r--r-- | server/tests/cli/create-import-video-file-job.ts | 168 | ||||
-rw-r--r-- | server/tests/cli/create-move-video-storage-job.ts | 124 | ||||
-rw-r--r-- | server/tests/cli/index.ts | 10 | ||||
-rw-r--r-- | server/tests/cli/peertube.ts | 331 | ||||
-rw-r--r-- | server/tests/cli/plugins.ts | 76 | ||||
-rw-r--r-- | server/tests/cli/prune-storage.ts | 223 | ||||
-rw-r--r-- | server/tests/cli/regenerate-thumbnails.ts | 122 | ||||
-rw-r--r-- | server/tests/cli/reset-password.ts | 26 | ||||
-rw-r--r-- | server/tests/cli/update-host.ts | 134 |
10 files changed, 0 insertions, 1334 deletions
diff --git a/server/tests/cli/create-generate-storyboard-job.ts b/server/tests/cli/create-generate-storyboard-job.ts deleted file mode 100644 index 02a4be8ae..000000000 --- a/server/tests/cli/create-generate-storyboard-job.ts +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { readdir, remove } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { HttpStatusCode } from '@shared/models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | createMultipleServers, | ||
10 | doubleFollow, | ||
11 | makeGetRequest, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { SQLCommand } from '../shared' | ||
17 | |||
18 | function listStoryboardFiles (server: PeerTubeServer) { | ||
19 | const storage = server.getDirectoryPath('storyboards') | ||
20 | |||
21 | return readdir(storage) | ||
22 | } | ||
23 | |||
24 | describe('Test create generate storyboard job', function () { | ||
25 | let servers: PeerTubeServer[] = [] | ||
26 | const uuids: string[] = [] | ||
27 | let sql: SQLCommand | ||
28 | let existingStoryboardName: string | ||
29 | |||
30 | before(async function () { | ||
31 | this.timeout(120000) | ||
32 | |||
33 | // Run server 2 to have transcoding enabled | ||
34 | servers = await createMultipleServers(2) | ||
35 | await setAccessTokensToServers(servers) | ||
36 | |||
37 | await doubleFollow(servers[0], servers[1]) | ||
38 | |||
39 | for (let i = 0; i < 3; i++) { | ||
40 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video ' + i }) | ||
41 | uuids.push(uuid) | ||
42 | } | ||
43 | |||
44 | await waitJobs(servers) | ||
45 | |||
46 | const storage = servers[0].getDirectoryPath('storyboards') | ||
47 | for (const storyboard of await listStoryboardFiles(servers[0])) { | ||
48 | await remove(join(storage, storyboard)) | ||
49 | } | ||
50 | |||
51 | sql = new SQLCommand(servers[0]) | ||
52 | await sql.deleteAll('storyboard') | ||
53 | |||
54 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 4' }) | ||
55 | uuids.push(uuid) | ||
56 | |||
57 | await waitJobs(servers) | ||
58 | |||
59 | const storyboards = await listStoryboardFiles(servers[0]) | ||
60 | existingStoryboardName = storyboards[0] | ||
61 | }) | ||
62 | |||
63 | it('Should create a storyboard of a video', async function () { | ||
64 | this.timeout(120000) | ||
65 | |||
66 | for (const uuid of [ uuids[0], uuids[3] ]) { | ||
67 | const command = `npm run create-generate-storyboard-job -- -v ${uuid}` | ||
68 | await servers[0].cli.execWithEnv(command) | ||
69 | } | ||
70 | |||
71 | await waitJobs(servers) | ||
72 | |||
73 | { | ||
74 | const storyboards = await listStoryboardFiles(servers[0]) | ||
75 | expect(storyboards).to.have.lengthOf(2) | ||
76 | expect(storyboards).to.not.include(existingStoryboardName) | ||
77 | |||
78 | existingStoryboardName = storyboards[0] | ||
79 | } | ||
80 | |||
81 | for (const server of servers) { | ||
82 | for (const uuid of [ uuids[0], uuids[3] ]) { | ||
83 | const { storyboards } = await server.storyboard.list({ id: uuid }) | ||
84 | expect(storyboards).to.have.lengthOf(1) | ||
85 | |||
86 | await makeGetRequest({ url: server.url, path: storyboards[0].storyboardPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
87 | } | ||
88 | } | ||
89 | }) | ||
90 | |||
91 | it('Should create missing storyboards', async function () { | ||
92 | this.timeout(120000) | ||
93 | |||
94 | const command = `npm run create-generate-storyboard-job -- -a` | ||
95 | await servers[0].cli.execWithEnv(command) | ||
96 | |||
97 | await waitJobs(servers) | ||
98 | |||
99 | { | ||
100 | const storyboards = await listStoryboardFiles(servers[0]) | ||
101 | expect(storyboards).to.have.lengthOf(4) | ||
102 | expect(storyboards).to.include(existingStoryboardName) | ||
103 | } | ||
104 | |||
105 | for (const server of servers) { | ||
106 | for (const uuid of uuids) { | ||
107 | const { storyboards } = await server.storyboard.list({ id: uuid }) | ||
108 | expect(storyboards).to.have.lengthOf(1) | ||
109 | |||
110 | await makeGetRequest({ url: server.url, path: storyboards[0].storyboardPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
111 | } | ||
112 | } | ||
113 | }) | ||
114 | |||
115 | after(async function () { | ||
116 | await sql.cleanup() | ||
117 | |||
118 | await cleanupTests(servers) | ||
119 | }) | ||
120 | }) | ||
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts deleted file mode 100644 index edd727967..000000000 --- a/server/tests/cli/create-import-video-file-job.ts +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | ||
5 | import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | makeRawRequest, | ||
11 | ObjectStorageCommand, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { expectStartWith } from '../shared' | ||
17 | |||
18 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | ||
19 | expect(video).to.have.nested.property('resolution.id', resolution) | ||
20 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) | ||
21 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | ||
22 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) | ||
23 | expect(video).to.have.property('size').that.is.above(0) | ||
24 | |||
25 | if (size) expect(video.size).to.equal(size) | ||
26 | } | ||
27 | |||
28 | async function checkFiles (video: VideoDetails, objectStorage: ObjectStorageCommand) { | ||
29 | for (const file of video.files) { | ||
30 | if (objectStorage) expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl()) | ||
31 | |||
32 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | function runTests (enableObjectStorage: boolean) { | ||
37 | let video1ShortId: string | ||
38 | let video2UUID: string | ||
39 | |||
40 | let servers: PeerTubeServer[] = [] | ||
41 | |||
42 | const objectStorage = new ObjectStorageCommand() | ||
43 | |||
44 | before(async function () { | ||
45 | this.timeout(90000) | ||
46 | |||
47 | const config = enableObjectStorage | ||
48 | ? objectStorage.getDefaultMockConfig() | ||
49 | : {} | ||
50 | |||
51 | // Run server 2 to have transcoding enabled | ||
52 | servers = await createMultipleServers(2, config) | ||
53 | await setAccessTokensToServers(servers) | ||
54 | |||
55 | await doubleFollow(servers[0], servers[1]) | ||
56 | |||
57 | if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets() | ||
58 | |||
59 | // Upload two videos for our needs | ||
60 | { | ||
61 | const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } }) | ||
62 | video1ShortId = shortUUID | ||
63 | } | ||
64 | |||
65 | { | ||
66 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } }) | ||
67 | video2UUID = uuid | ||
68 | } | ||
69 | |||
70 | await waitJobs(servers) | ||
71 | |||
72 | for (const server of servers) { | ||
73 | await server.config.enableTranscoding() | ||
74 | } | ||
75 | }) | ||
76 | |||
77 | it('Should run a import job on video 1 with a lower resolution', async function () { | ||
78 | const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short_480.webm` | ||
79 | await servers[0].cli.execWithEnv(command) | ||
80 | |||
81 | await waitJobs(servers) | ||
82 | |||
83 | for (const server of servers) { | ||
84 | const { data: videos } = await server.videos.list() | ||
85 | expect(videos).to.have.lengthOf(2) | ||
86 | |||
87 | const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId) | ||
88 | const videoDetails = await server.videos.get({ id: video.shortUUID }) | ||
89 | |||
90 | expect(videoDetails.files).to.have.lengthOf(2) | ||
91 | const [ originalVideo, transcodedVideo ] = videoDetails.files | ||
92 | assertVideoProperties(originalVideo, 720, 'webm', 218910) | ||
93 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | ||
94 | |||
95 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
96 | } | ||
97 | }) | ||
98 | |||
99 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { | ||
100 | const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv` | ||
101 | await servers[1].cli.execWithEnv(command) | ||
102 | |||
103 | await waitJobs(servers) | ||
104 | |||
105 | for (const server of servers) { | ||
106 | const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE }) | ||
107 | expect(videos).to.have.lengthOf(2) | ||
108 | |||
109 | const video = videos.find(({ uuid }) => uuid === video2UUID) | ||
110 | const videoDetails = await server.videos.get({ id: video.uuid }) | ||
111 | |||
112 | expect(videoDetails.files).to.have.lengthOf(4) | ||
113 | const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files | ||
114 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) | ||
115 | assertVideoProperties(transcodedVideo420, 480, 'mp4') | ||
116 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | ||
117 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | ||
118 | |||
119 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
120 | } | ||
121 | }) | ||
122 | |||
123 | it('Should run a import job on video 2 with the same resolution and the same extension', async function () { | ||
124 | const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm` | ||
125 | await servers[0].cli.execWithEnv(command) | ||
126 | |||
127 | await waitJobs(servers) | ||
128 | |||
129 | for (const server of servers) { | ||
130 | const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE }) | ||
131 | expect(videos).to.have.lengthOf(2) | ||
132 | |||
133 | const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId) | ||
134 | const videoDetails = await server.videos.get({ id: video.uuid }) | ||
135 | |||
136 | expect(videoDetails.files).to.have.lengthOf(2) | ||
137 | const [ video720, video480 ] = videoDetails.files | ||
138 | assertVideoProperties(video720, 720, 'webm', 942961) | ||
139 | assertVideoProperties(video480, 480, 'webm', 69217) | ||
140 | |||
141 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
142 | } | ||
143 | }) | ||
144 | |||
145 | it('Should not have run transcoding after an import job', async function () { | ||
146 | const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' }) | ||
147 | expect(data).to.have.lengthOf(0) | ||
148 | }) | ||
149 | |||
150 | after(async function () { | ||
151 | await objectStorage.cleanupMock() | ||
152 | |||
153 | await cleanupTests(servers) | ||
154 | }) | ||
155 | } | ||
156 | |||
157 | describe('Test create import video jobs', function () { | ||
158 | |||
159 | describe('On filesystem', function () { | ||
160 | runTests(false) | ||
161 | }) | ||
162 | |||
163 | describe('On object storage', function () { | ||
164 | if (areMockObjectStorageTestsDisabled()) return | ||
165 | |||
166 | runTests(true) | ||
167 | }) | ||
168 | }) | ||
diff --git a/server/tests/cli/create-move-video-storage-job.ts b/server/tests/cli/create-move-video-storage-job.ts deleted file mode 100644 index fc6a8e648..000000000 --- a/server/tests/cli/create-move-video-storage-job.ts +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { join } from 'path' | ||
4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | ||
5 | import { HttpStatusCode, VideoDetails } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | makeRawRequest, | ||
11 | ObjectStorageCommand, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { checkDirectoryIsEmpty, expectStartWith } from '../shared' | ||
17 | |||
18 | async function checkFiles (origin: PeerTubeServer, video: VideoDetails, objectStorage?: ObjectStorageCommand) { | ||
19 | for (const file of video.files) { | ||
20 | const start = objectStorage | ||
21 | ? objectStorage.getMockWebVideosBaseUrl() | ||
22 | : origin.url | ||
23 | |||
24 | expectStartWith(file.fileUrl, start) | ||
25 | |||
26 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
27 | } | ||
28 | |||
29 | const start = objectStorage | ||
30 | ? objectStorage.getMockPlaylistBaseUrl() | ||
31 | : origin.url | ||
32 | |||
33 | const hls = video.streamingPlaylists[0] | ||
34 | expectStartWith(hls.playlistUrl, start) | ||
35 | expectStartWith(hls.segmentsSha256Url, start) | ||
36 | |||
37 | for (const file of hls.files) { | ||
38 | expectStartWith(file.fileUrl, start) | ||
39 | |||
40 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | describe('Test create move video storage job', function () { | ||
45 | if (areMockObjectStorageTestsDisabled()) return | ||
46 | |||
47 | let servers: PeerTubeServer[] = [] | ||
48 | const uuids: string[] = [] | ||
49 | const objectStorage = new ObjectStorageCommand() | ||
50 | |||
51 | before(async function () { | ||
52 | this.timeout(360000) | ||
53 | |||
54 | // Run server 2 to have transcoding enabled | ||
55 | servers = await createMultipleServers(2) | ||
56 | await setAccessTokensToServers(servers) | ||
57 | |||
58 | await doubleFollow(servers[0], servers[1]) | ||
59 | |||
60 | await objectStorage.prepareDefaultMockBuckets() | ||
61 | |||
62 | await servers[0].config.enableTranscoding() | ||
63 | |||
64 | for (let i = 0; i < 3; i++) { | ||
65 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } }) | ||
66 | uuids.push(uuid) | ||
67 | } | ||
68 | |||
69 | await waitJobs(servers) | ||
70 | |||
71 | await servers[0].kill() | ||
72 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
73 | }) | ||
74 | |||
75 | it('Should move only one file', async function () { | ||
76 | this.timeout(120000) | ||
77 | |||
78 | const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}` | ||
79 | await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig()) | ||
80 | await waitJobs(servers) | ||
81 | |||
82 | for (const server of servers) { | ||
83 | const video = await server.videos.get({ id: uuids[1] }) | ||
84 | |||
85 | await checkFiles(servers[0], video, objectStorage) | ||
86 | |||
87 | for (const id of [ uuids[0], uuids[2] ]) { | ||
88 | const video = await server.videos.get({ id }) | ||
89 | |||
90 | await checkFiles(servers[0], video) | ||
91 | } | ||
92 | } | ||
93 | }) | ||
94 | |||
95 | it('Should move all files', async function () { | ||
96 | this.timeout(120000) | ||
97 | |||
98 | const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos` | ||
99 | await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig()) | ||
100 | await waitJobs(servers) | ||
101 | |||
102 | for (const server of servers) { | ||
103 | for (const id of [ uuids[0], uuids[2] ]) { | ||
104 | const video = await server.videos.get({ id }) | ||
105 | |||
106 | await checkFiles(servers[0], video, objectStorage) | ||
107 | } | ||
108 | } | ||
109 | }) | ||
110 | |||
111 | it('Should not have files on disk anymore', async function () { | ||
112 | await checkDirectoryIsEmpty(servers[0], 'web-videos', [ 'private' ]) | ||
113 | await checkDirectoryIsEmpty(servers[0], join('web-videos', 'private')) | ||
114 | |||
115 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ]) | ||
116 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private')) | ||
117 | }) | ||
118 | |||
119 | after(async function () { | ||
120 | await objectStorage.cleanupMock() | ||
121 | |||
122 | await cleanupTests(servers) | ||
123 | }) | ||
124 | }) | ||
diff --git a/server/tests/cli/index.ts b/server/tests/cli/index.ts deleted file mode 100644 index 94444ace3..000000000 --- a/server/tests/cli/index.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './create-import-video-file-job' | ||
3 | import './create-generate-storyboard-job' | ||
4 | import './create-move-video-storage-job' | ||
5 | import './peertube' | ||
6 | import './plugins' | ||
7 | import './prune-storage' | ||
8 | import './regenerate-thumbnails' | ||
9 | import './reset-password' | ||
10 | import './update-host' | ||
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts deleted file mode 100644 index ad14fde91..000000000 --- a/server/tests/cli/peertube.ts +++ /dev/null | |||
@@ -1,331 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | CLICommand, | ||
8 | createSingleServer, | ||
9 | doubleFollow, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | waitJobs | ||
13 | } from '@shared/server-commands' | ||
14 | import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared' | ||
15 | |||
16 | describe('Test CLI wrapper', function () { | ||
17 | let server: PeerTubeServer | ||
18 | let userAccessToken: string | ||
19 | |||
20 | let cliCommand: CLICommand | ||
21 | |||
22 | const cmd = 'node ./dist/server/tools/peertube.js' | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(30000) | ||
26 | |||
27 | server = await createSingleServer(1, { | ||
28 | rates_limit: { | ||
29 | login: { | ||
30 | max: 30 | ||
31 | } | ||
32 | } | ||
33 | }) | ||
34 | await setAccessTokensToServers([ server ]) | ||
35 | |||
36 | await server.users.create({ username: 'user_1', password: 'super_password' }) | ||
37 | |||
38 | userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' }) | ||
39 | |||
40 | { | ||
41 | const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } | ||
42 | await server.channels.create({ token: userAccessToken, attributes }) | ||
43 | } | ||
44 | |||
45 | cliCommand = server.cli | ||
46 | }) | ||
47 | |||
48 | describe('Authentication and instance selection', function () { | ||
49 | |||
50 | it('Should get an access token', async function () { | ||
51 | const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`) | ||
52 | const token = stdout.trim() | ||
53 | |||
54 | const body = await server.users.getMyInfo({ token }) | ||
55 | expect(body.username).to.equal('user_1') | ||
56 | }) | ||
57 | |||
58 | it('Should display no selected instance', async function () { | ||
59 | this.timeout(60000) | ||
60 | |||
61 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) | ||
62 | expect(stdout).to.contain('no instance selected') | ||
63 | }) | ||
64 | |||
65 | it('Should add a user', async function () { | ||
66 | this.timeout(60000) | ||
67 | |||
68 | await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | ||
69 | }) | ||
70 | |||
71 | it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () { | ||
72 | this.timeout(60000) | ||
73 | |||
74 | let fullServerURL = server.url + '/' | ||
75 | |||
76 | await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) | ||
77 | |||
78 | fullServerURL = server.url + '/asdfasdf' | ||
79 | await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) | ||
80 | }) | ||
81 | |||
82 | it('Should default to this user', async function () { | ||
83 | this.timeout(60000) | ||
84 | |||
85 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) | ||
86 | expect(stdout).to.contain(`instance ${server.url} selected`) | ||
87 | }) | ||
88 | |||
89 | it('Should remember the user', async function () { | ||
90 | this.timeout(60000) | ||
91 | |||
92 | const stdout = await cliCommand.execWithEnv(`${cmd} auth list`) | ||
93 | expect(stdout).to.contain(server.url) | ||
94 | }) | ||
95 | }) | ||
96 | |||
97 | describe('Video upload/import', function () { | ||
98 | |||
99 | it('Should upload a video', async function () { | ||
100 | this.timeout(60000) | ||
101 | |||
102 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') | ||
103 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` | ||
104 | |||
105 | await cliCommand.execWithEnv(`${cmd} upload ${params}`) | ||
106 | }) | ||
107 | |||
108 | it('Should have the video uploaded', async function () { | ||
109 | const { total, data } = await server.videos.list() | ||
110 | expect(total).to.equal(1) | ||
111 | |||
112 | const video = await server.videos.get({ id: data[0].uuid }) | ||
113 | expect(video.name).to.equal('test upload') | ||
114 | expect(video.support).to.equal('support_text') | ||
115 | expect(video.channel.name).to.equal('user_channel') | ||
116 | }) | ||
117 | |||
118 | it('Should import a video', async function () { | ||
119 | if (areHttpImportTestsDisabled()) return | ||
120 | |||
121 | this.timeout(60000) | ||
122 | |||
123 | const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel` | ||
124 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | ||
125 | }) | ||
126 | |||
127 | it('Should have imported the video', async function () { | ||
128 | if (areHttpImportTestsDisabled()) return | ||
129 | |||
130 | this.timeout(60000) | ||
131 | |||
132 | await waitJobs([ server ]) | ||
133 | |||
134 | const { total, data } = await server.videos.list() | ||
135 | expect(total).to.equal(2) | ||
136 | |||
137 | const video = data.find(v => v.name === 'small video - youtube') | ||
138 | expect(video).to.not.be.undefined | ||
139 | |||
140 | const videoDetails = await server.videos.get({ id: video.id }) | ||
141 | expect(videoDetails.channel.name).to.equal('user_channel') | ||
142 | expect(videoDetails.support).to.equal('super support text') | ||
143 | expect(videoDetails.nsfw).to.be.false | ||
144 | }) | ||
145 | |||
146 | it('Should not import again the same video', async function () { | ||
147 | if (areHttpImportTestsDisabled()) return | ||
148 | |||
149 | this.timeout(60000) | ||
150 | |||
151 | const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel` | ||
152 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | ||
153 | |||
154 | await waitJobs([ server ]) | ||
155 | |||
156 | const { total, data } = await server.videos.list() | ||
157 | expect(total).to.equal(2) | ||
158 | |||
159 | const videos = data.filter(v => v.name === 'small video - youtube') | ||
160 | expect(videos).to.have.lengthOf(1) | ||
161 | |||
162 | // So we can reimport it | ||
163 | await server.videos.remove({ token: userAccessToken, id: videos[0].id }) | ||
164 | }) | ||
165 | |||
166 | it('Should import and override some imported attributes', async function () { | ||
167 | if (areHttpImportTestsDisabled()) return | ||
168 | |||
169 | this.timeout(60000) | ||
170 | |||
171 | const params = `--target-url ${FIXTURE_URLS.youtube} ` + | ||
172 | `--channel-name user_channel --video-name toto --nsfw --support support` | ||
173 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | ||
174 | |||
175 | await waitJobs([ server ]) | ||
176 | |||
177 | { | ||
178 | const { total, data } = await server.videos.list() | ||
179 | expect(total).to.equal(2) | ||
180 | |||
181 | const video = data.find(v => v.name === 'toto') | ||
182 | expect(video).to.not.be.undefined | ||
183 | |||
184 | const videoDetails = await server.videos.get({ id: video.id }) | ||
185 | expect(videoDetails.channel.name).to.equal('user_channel') | ||
186 | expect(videoDetails.support).to.equal('support') | ||
187 | expect(videoDetails.nsfw).to.be.true | ||
188 | expect(videoDetails.commentsEnabled).to.be.true | ||
189 | } | ||
190 | }) | ||
191 | }) | ||
192 | |||
193 | describe('Admin auth', function () { | ||
194 | |||
195 | it('Should remove the auth user', async function () { | ||
196 | await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`) | ||
197 | |||
198 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) | ||
199 | expect(stdout).to.contain('no instance selected') | ||
200 | }) | ||
201 | |||
202 | it('Should add the admin user', async function () { | ||
203 | await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) | ||
204 | }) | ||
205 | }) | ||
206 | |||
207 | describe('Manage plugins', function () { | ||
208 | |||
209 | it('Should install a plugin', async function () { | ||
210 | this.timeout(60000) | ||
211 | |||
212 | await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`) | ||
213 | }) | ||
214 | |||
215 | it('Should have registered settings', async function () { | ||
216 | await testHelloWorldRegisteredSettings(server) | ||
217 | }) | ||
218 | |||
219 | it('Should list installed plugins', async function () { | ||
220 | const res = await cliCommand.execWithEnv(`${cmd} plugins list`) | ||
221 | |||
222 | expect(res).to.contain('peertube-plugin-hello-world') | ||
223 | }) | ||
224 | |||
225 | it('Should uninstall the plugin', async function () { | ||
226 | const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
227 | |||
228 | expect(res).to.not.contain('peertube-plugin-hello-world') | ||
229 | }) | ||
230 | |||
231 | it('Should install a plugin in requested version', async function () { | ||
232 | this.timeout(60000) | ||
233 | |||
234 | await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`) | ||
235 | }) | ||
236 | |||
237 | it('Should list installed plugins, in correct version', async function () { | ||
238 | const res = await cliCommand.execWithEnv(`${cmd} plugins list`) | ||
239 | |||
240 | expect(res).to.contain('peertube-plugin-hello-world') | ||
241 | expect(res).to.contain('0.0.17') | ||
242 | }) | ||
243 | |||
244 | it('Should uninstall the plugin again', async function () { | ||
245 | const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
246 | |||
247 | expect(res).to.not.contain('peertube-plugin-hello-world') | ||
248 | }) | ||
249 | |||
250 | it('Should install a plugin in requested beta version', async function () { | ||
251 | this.timeout(60000) | ||
252 | |||
253 | await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.21-beta.1`) | ||
254 | |||
255 | const res = await cliCommand.execWithEnv(`${cmd} plugins list`) | ||
256 | |||
257 | expect(res).to.contain('peertube-plugin-hello-world') | ||
258 | expect(res).to.contain('0.0.21-beta.1') | ||
259 | |||
260 | await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
261 | }) | ||
262 | }) | ||
263 | |||
264 | describe('Manage video redundancies', function () { | ||
265 | let anotherServer: PeerTubeServer | ||
266 | let video1Server2: number | ||
267 | let servers: PeerTubeServer[] | ||
268 | |||
269 | before(async function () { | ||
270 | this.timeout(120000) | ||
271 | |||
272 | anotherServer = await createSingleServer(2) | ||
273 | await setAccessTokensToServers([ anotherServer ]) | ||
274 | |||
275 | await doubleFollow(server, anotherServer) | ||
276 | |||
277 | servers = [ server, anotherServer ] | ||
278 | await waitJobs(servers) | ||
279 | |||
280 | const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' }) | ||
281 | await waitJobs(servers) | ||
282 | |||
283 | video1Server2 = await server.videos.getId({ uuid }) | ||
284 | }) | ||
285 | |||
286 | it('Should add a redundancy', async function () { | ||
287 | this.timeout(60000) | ||
288 | |||
289 | const params = `add --video ${video1Server2}` | ||
290 | await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | ||
291 | |||
292 | await waitJobs(servers) | ||
293 | }) | ||
294 | |||
295 | it('Should list redundancies', async function () { | ||
296 | this.timeout(60000) | ||
297 | |||
298 | { | ||
299 | const params = 'list-my-redundancies' | ||
300 | const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | ||
301 | |||
302 | expect(stdout).to.contain('super video') | ||
303 | expect(stdout).to.contain(server.host) | ||
304 | } | ||
305 | }) | ||
306 | |||
307 | it('Should remove a redundancy', async function () { | ||
308 | this.timeout(60000) | ||
309 | |||
310 | const params = `remove --video ${video1Server2}` | ||
311 | await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | ||
312 | |||
313 | await waitJobs(servers) | ||
314 | |||
315 | { | ||
316 | const params = 'list-my-redundancies' | ||
317 | const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | ||
318 | |||
319 | expect(stdout).to.not.contain('super video') | ||
320 | } | ||
321 | }) | ||
322 | |||
323 | after(async function () { | ||
324 | await cleanupTests([ anotherServer ]) | ||
325 | }) | ||
326 | }) | ||
327 | |||
328 | after(async function () { | ||
329 | await cleanupTests([ server ]) | ||
330 | }) | ||
331 | }) | ||
diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts deleted file mode 100644 index c646e20d9..000000000 --- a/server/tests/cli/plugins.ts +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createSingleServer, | ||
7 | killallServers, | ||
8 | PeerTubeServer, | ||
9 | PluginsCommand, | ||
10 | setAccessTokensToServers | ||
11 | } from '@shared/server-commands' | ||
12 | |||
13 | describe('Test plugin scripts', function () { | ||
14 | let server: PeerTubeServer | ||
15 | |||
16 | before(async function () { | ||
17 | this.timeout(30000) | ||
18 | |||
19 | server = await createSingleServer(1) | ||
20 | await setAccessTokensToServers([ server ]) | ||
21 | }) | ||
22 | |||
23 | it('Should install a plugin from stateless CLI', async function () { | ||
24 | this.timeout(60000) | ||
25 | |||
26 | const packagePath = PluginsCommand.getPluginTestPath() | ||
27 | |||
28 | await server.cli.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`) | ||
29 | }) | ||
30 | |||
31 | it('Should install a theme from stateless CLI', async function () { | ||
32 | this.timeout(60000) | ||
33 | |||
34 | await server.cli.execWithEnv(`npm run plugin:install -- --npm-name peertube-theme-background-red`) | ||
35 | }) | ||
36 | |||
37 | it('Should have the theme and the plugin registered when we restart peertube', async function () { | ||
38 | this.timeout(30000) | ||
39 | |||
40 | await killallServers([ server ]) | ||
41 | await server.run() | ||
42 | |||
43 | const config = await server.config.getConfig() | ||
44 | |||
45 | const plugin = config.plugin.registered | ||
46 | .find(p => p.name === 'test') | ||
47 | expect(plugin).to.not.be.undefined | ||
48 | |||
49 | const theme = config.theme.registered | ||
50 | .find(t => t.name === 'background-red') | ||
51 | expect(theme).to.not.be.undefined | ||
52 | }) | ||
53 | |||
54 | it('Should uninstall a plugin from stateless CLI', async function () { | ||
55 | this.timeout(60000) | ||
56 | |||
57 | await server.cli.execWithEnv(`npm run plugin:uninstall -- --npm-name peertube-plugin-test`) | ||
58 | }) | ||
59 | |||
60 | it('Should have removed the plugin on another peertube restart', async function () { | ||
61 | this.timeout(30000) | ||
62 | |||
63 | await killallServers([ server ]) | ||
64 | await server.run() | ||
65 | |||
66 | const config = await server.config.getConfig() | ||
67 | |||
68 | const plugin = config.plugin.registered | ||
69 | .find(p => p.name === 'test') | ||
70 | expect(plugin).to.be.undefined | ||
71 | }) | ||
72 | |||
73 | after(async function () { | ||
74 | await cleanupTests([ server ]) | ||
75 | }) | ||
76 | }) | ||
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts deleted file mode 100644 index 72a4b1332..000000000 --- a/server/tests/cli/prune-storage.ts +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { createFile, readdir } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { wait } from '@shared/core-utils' | ||
7 | import { buildUUID } from '@shared/extra-utils' | ||
8 | import { HttpStatusCode, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | ||
9 | import { | ||
10 | cleanupTests, | ||
11 | CLICommand, | ||
12 | createMultipleServers, | ||
13 | doubleFollow, | ||
14 | killallServers, | ||
15 | makeGetRequest, | ||
16 | PeerTubeServer, | ||
17 | setAccessTokensToServers, | ||
18 | setDefaultVideoChannel, | ||
19 | waitJobs | ||
20 | } from '@shared/server-commands' | ||
21 | |||
22 | async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) { | ||
23 | const files = await readdir(server.servers.buildDirectory(directory)) | ||
24 | |||
25 | for (const f of files) { | ||
26 | expect(f).to.not.contain(substring) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | async function assertCountAreOkay (servers: PeerTubeServer[]) { | ||
31 | for (const server of servers) { | ||
32 | const videosCount = await server.servers.countFiles('web-videos') | ||
33 | expect(videosCount).to.equal(9) // 2 videos with 4 resolutions + private directory | ||
34 | |||
35 | const privateVideosCount = await server.servers.countFiles('web-videos/private') | ||
36 | expect(privateVideosCount).to.equal(4) | ||
37 | |||
38 | const torrentsCount = await server.servers.countFiles('torrents') | ||
39 | expect(torrentsCount).to.equal(24) | ||
40 | |||
41 | const previewsCount = await server.servers.countFiles('previews') | ||
42 | expect(previewsCount).to.equal(3) | ||
43 | |||
44 | const thumbnailsCount = await server.servers.countFiles('thumbnails') | ||
45 | expect(thumbnailsCount).to.equal(5) // 3 local videos, 1 local playlist, 2 remotes videos (lazy downloaded) and 1 remote playlist | ||
46 | |||
47 | const avatarsCount = await server.servers.countFiles('avatars') | ||
48 | expect(avatarsCount).to.equal(4) | ||
49 | |||
50 | const hlsRootCount = await server.servers.countFiles(join('streaming-playlists', 'hls')) | ||
51 | expect(hlsRootCount).to.equal(3) // 2 videos + private directory | ||
52 | |||
53 | const hlsPrivateRootCount = await server.servers.countFiles(join('streaming-playlists', 'hls', 'private')) | ||
54 | expect(hlsPrivateRootCount).to.equal(1) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | describe('Test prune storage scripts', function () { | ||
59 | let servers: PeerTubeServer[] | ||
60 | const badNames: { [directory: string]: string[] } = {} | ||
61 | |||
62 | before(async function () { | ||
63 | this.timeout(120000) | ||
64 | |||
65 | servers = await createMultipleServers(2, { transcoding: { enabled: true } }) | ||
66 | await setAccessTokensToServers(servers) | ||
67 | await setDefaultVideoChannel(servers) | ||
68 | |||
69 | for (const server of servers) { | ||
70 | await server.videos.upload({ attributes: { name: 'video 1', privacy: VideoPrivacy.PUBLIC } }) | ||
71 | await server.videos.upload({ attributes: { name: 'video 2', privacy: VideoPrivacy.PUBLIC } }) | ||
72 | |||
73 | await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } }) | ||
74 | |||
75 | await server.users.updateMyAvatar({ fixture: 'avatar.png' }) | ||
76 | |||
77 | await server.playlists.create({ | ||
78 | attributes: { | ||
79 | displayName: 'playlist', | ||
80 | privacy: VideoPlaylistPrivacy.PUBLIC, | ||
81 | videoChannelId: server.store.channel.id, | ||
82 | thumbnailfile: 'custom-thumbnail.jpg' | ||
83 | } | ||
84 | }) | ||
85 | } | ||
86 | |||
87 | await doubleFollow(servers[0], servers[1]) | ||
88 | |||
89 | // Lazy load the remote avatars | ||
90 | { | ||
91 | const account = await servers[0].accounts.get({ accountName: 'root@' + servers[1].host }) | ||
92 | |||
93 | for (const avatar of account.avatars) { | ||
94 | await makeGetRequest({ | ||
95 | url: servers[0].url, | ||
96 | path: avatar.path, | ||
97 | expectedStatus: HttpStatusCode.OK_200 | ||
98 | }) | ||
99 | } | ||
100 | } | ||
101 | |||
102 | { | ||
103 | const account = await servers[1].accounts.get({ accountName: 'root@' + servers[0].host }) | ||
104 | for (const avatar of account.avatars) { | ||
105 | await makeGetRequest({ | ||
106 | url: servers[1].url, | ||
107 | path: avatar.path, | ||
108 | expectedStatus: HttpStatusCode.OK_200 | ||
109 | }) | ||
110 | } | ||
111 | } | ||
112 | |||
113 | await wait(1000) | ||
114 | |||
115 | await waitJobs(servers) | ||
116 | await killallServers(servers) | ||
117 | |||
118 | await wait(1000) | ||
119 | }) | ||
120 | |||
121 | it('Should have the files on the disk', async function () { | ||
122 | await assertCountAreOkay(servers) | ||
123 | }) | ||
124 | |||
125 | it('Should create some dirty files', async function () { | ||
126 | for (let i = 0; i < 2; i++) { | ||
127 | { | ||
128 | const basePublic = servers[0].servers.buildDirectory('web-videos') | ||
129 | const basePrivate = servers[0].servers.buildDirectory(join('web-videos', 'private')) | ||
130 | |||
131 | const n1 = buildUUID() + '.mp4' | ||
132 | const n2 = buildUUID() + '.webm' | ||
133 | |||
134 | await createFile(join(basePublic, n1)) | ||
135 | await createFile(join(basePublic, n2)) | ||
136 | await createFile(join(basePrivate, n1)) | ||
137 | await createFile(join(basePrivate, n2)) | ||
138 | |||
139 | badNames['web-videos'] = [ n1, n2 ] | ||
140 | } | ||
141 | |||
142 | { | ||
143 | const base = servers[0].servers.buildDirectory('torrents') | ||
144 | |||
145 | const n1 = buildUUID() + '-240.torrent' | ||
146 | const n2 = buildUUID() + '-480.torrent' | ||
147 | |||
148 | await createFile(join(base, n1)) | ||
149 | await createFile(join(base, n2)) | ||
150 | |||
151 | badNames['torrents'] = [ n1, n2 ] | ||
152 | } | ||
153 | |||
154 | { | ||
155 | const base = servers[0].servers.buildDirectory('thumbnails') | ||
156 | |||
157 | const n1 = buildUUID() + '.jpg' | ||
158 | const n2 = buildUUID() + '.jpg' | ||
159 | |||
160 | await createFile(join(base, n1)) | ||
161 | await createFile(join(base, n2)) | ||
162 | |||
163 | badNames['thumbnails'] = [ n1, n2 ] | ||
164 | } | ||
165 | |||
166 | { | ||
167 | const base = servers[0].servers.buildDirectory('previews') | ||
168 | |||
169 | const n1 = buildUUID() + '.jpg' | ||
170 | const n2 = buildUUID() + '.jpg' | ||
171 | |||
172 | await createFile(join(base, n1)) | ||
173 | await createFile(join(base, n2)) | ||
174 | |||
175 | badNames['previews'] = [ n1, n2 ] | ||
176 | } | ||
177 | |||
178 | { | ||
179 | const base = servers[0].servers.buildDirectory('avatars') | ||
180 | |||
181 | const n1 = buildUUID() + '.png' | ||
182 | const n2 = buildUUID() + '.jpg' | ||
183 | |||
184 | await createFile(join(base, n1)) | ||
185 | await createFile(join(base, n2)) | ||
186 | |||
187 | badNames['avatars'] = [ n1, n2 ] | ||
188 | } | ||
189 | |||
190 | { | ||
191 | const directory = join('streaming-playlists', 'hls') | ||
192 | const basePublic = servers[0].servers.buildDirectory(directory) | ||
193 | const basePrivate = servers[0].servers.buildDirectory(join(directory, 'private')) | ||
194 | |||
195 | const n1 = buildUUID() | ||
196 | await createFile(join(basePublic, n1)) | ||
197 | await createFile(join(basePrivate, n1)) | ||
198 | badNames[directory] = [ n1 ] | ||
199 | } | ||
200 | } | ||
201 | }) | ||
202 | |||
203 | it('Should run prune storage', async function () { | ||
204 | this.timeout(30000) | ||
205 | |||
206 | const env = servers[0].cli.getEnv() | ||
207 | await CLICommand.exec(`echo y | ${env} npm run prune-storage`) | ||
208 | }) | ||
209 | |||
210 | it('Should have removed files', async function () { | ||
211 | await assertCountAreOkay(servers) | ||
212 | |||
213 | for (const directory of Object.keys(badNames)) { | ||
214 | for (const name of badNames[directory]) { | ||
215 | await assertNotExists(servers[0], directory, name) | ||
216 | } | ||
217 | } | ||
218 | }) | ||
219 | |||
220 | after(async function () { | ||
221 | await cleanupTests(servers) | ||
222 | }) | ||
223 | }) | ||
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts deleted file mode 100644 index 66de7f79c..000000000 --- a/server/tests/cli/regenerate-thumbnails.ts +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | import { expect } from 'chai' | ||
2 | import { writeFile } from 'fs-extra' | ||
3 | import { basename, join } from 'path' | ||
4 | import { HttpStatusCode, Video } from '@shared/models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | makeGetRequest, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | waitJobs | ||
13 | } from '../../../shared/server-commands' | ||
14 | |||
15 | async function testThumbnail (server: PeerTubeServer, videoId: number | string) { | ||
16 | const video = await server.videos.get({ id: videoId }) | ||
17 | |||
18 | const requests = [ | ||
19 | makeGetRequest({ url: server.url, path: video.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }), | ||
20 | makeGetRequest({ url: server.url, path: video.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
21 | ] | ||
22 | |||
23 | for (const req of requests) { | ||
24 | const res = await req | ||
25 | expect(res.body).to.not.have.lengthOf(0) | ||
26 | } | ||
27 | } | ||
28 | |||
29 | describe('Test regenerate thumbnails script', function () { | ||
30 | let servers: PeerTubeServer[] | ||
31 | |||
32 | let video1: Video | ||
33 | let video2: Video | ||
34 | let remoteVideo: Video | ||
35 | |||
36 | let thumbnail1Path: string | ||
37 | let thumbnailRemotePath: string | ||
38 | |||
39 | before(async function () { | ||
40 | this.timeout(60000) | ||
41 | |||
42 | servers = await createMultipleServers(2) | ||
43 | await setAccessTokensToServers(servers) | ||
44 | |||
45 | await doubleFollow(servers[0], servers[1]) | ||
46 | |||
47 | { | ||
48 | const videoUUID1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid | ||
49 | video1 = await servers[0].videos.get({ id: videoUUID1 }) | ||
50 | |||
51 | thumbnail1Path = join(servers[0].servers.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) | ||
52 | |||
53 | const videoUUID2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid | ||
54 | video2 = await servers[0].videos.get({ id: videoUUID2 }) | ||
55 | } | ||
56 | |||
57 | { | ||
58 | const videoUUID = (await servers[1].videos.quickUpload({ name: 'video 3' })).uuid | ||
59 | await waitJobs(servers) | ||
60 | |||
61 | remoteVideo = await servers[0].videos.get({ id: videoUUID }) | ||
62 | |||
63 | // Load remote thumbnail on disk | ||
64 | await makeGetRequest({ url: servers[0].url, path: remoteVideo.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
65 | |||
66 | thumbnailRemotePath = join(servers[0].servers.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) | ||
67 | } | ||
68 | |||
69 | await writeFile(thumbnail1Path, '') | ||
70 | await writeFile(thumbnailRemotePath, '') | ||
71 | }) | ||
72 | |||
73 | it('Should have empty thumbnails', async function () { | ||
74 | { | ||
75 | const res = await makeGetRequest({ url: servers[0].url, path: video1.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
76 | expect(res.body).to.have.lengthOf(0) | ||
77 | } | ||
78 | |||
79 | { | ||
80 | const res = await makeGetRequest({ url: servers[0].url, path: video2.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
81 | expect(res.body).to.not.have.lengthOf(0) | ||
82 | } | ||
83 | |||
84 | { | ||
85 | const res = await makeGetRequest({ url: servers[0].url, path: remoteVideo.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
86 | expect(res.body).to.have.lengthOf(0) | ||
87 | } | ||
88 | }) | ||
89 | |||
90 | it('Should regenerate local thumbnails from the CLI', async function () { | ||
91 | this.timeout(15000) | ||
92 | |||
93 | await servers[0].cli.execWithEnv(`npm run regenerate-thumbnails`) | ||
94 | }) | ||
95 | |||
96 | it('Should have generated new thumbnail files', async function () { | ||
97 | await testThumbnail(servers[0], video1.uuid) | ||
98 | await testThumbnail(servers[0], video2.uuid) | ||
99 | |||
100 | const res = await makeGetRequest({ url: servers[0].url, path: remoteVideo.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
101 | expect(res.body).to.have.lengthOf(0) | ||
102 | }) | ||
103 | |||
104 | it('Should have deleted old thumbnail files', async function () { | ||
105 | { | ||
106 | await makeGetRequest({ url: servers[0].url, path: video1.thumbnailPath, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | ||
107 | } | ||
108 | |||
109 | { | ||
110 | await makeGetRequest({ url: servers[0].url, path: video2.thumbnailPath, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | ||
111 | } | ||
112 | |||
113 | { | ||
114 | const res = await makeGetRequest({ url: servers[0].url, path: remoteVideo.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | ||
115 | expect(res.body).to.have.lengthOf(0) | ||
116 | } | ||
117 | }) | ||
118 | |||
119 | after(async function () { | ||
120 | await cleanupTests(servers) | ||
121 | }) | ||
122 | }) | ||
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts deleted file mode 100644 index 79892173b..000000000 --- a/server/tests/cli/reset-password.ts +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
2 | |||
3 | describe('Test reset password scripts', function () { | ||
4 | let server: PeerTubeServer | ||
5 | |||
6 | before(async function () { | ||
7 | this.timeout(30000) | ||
8 | server = await createSingleServer(1) | ||
9 | await setAccessTokensToServers([ server ]) | ||
10 | |||
11 | await server.users.create({ username: 'user_1', password: 'super password' }) | ||
12 | }) | ||
13 | |||
14 | it('Should change the user password from CLI', async function () { | ||
15 | this.timeout(60000) | ||
16 | |||
17 | const env = server.cli.getEnv() | ||
18 | await CLICommand.exec(`echo coucou | ${env} npm run reset-password -- -u user_1`) | ||
19 | |||
20 | await server.login.login({ user: { username: 'user_1', password: 'coucou' } }) | ||
21 | }) | ||
22 | |||
23 | after(async function () { | ||
24 | await cleanupTests([ server ]) | ||
25 | }) | ||
26 | }) | ||
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts deleted file mode 100644 index 386c384e6..000000000 --- a/server/tests/cli/update-host.ts +++ /dev/null | |||
@@ -1,134 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { getAllFiles } from '@shared/core-utils' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | killallServers, | ||
9 | makeActivityPubGetRequest, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | waitJobs | ||
13 | } from '@shared/server-commands' | ||
14 | import { parseTorrentVideo } from '../shared' | ||
15 | |||
16 | describe('Test update host scripts', function () { | ||
17 | let server: PeerTubeServer | ||
18 | |||
19 | before(async function () { | ||
20 | this.timeout(60000) | ||
21 | |||
22 | const overrideConfig = { | ||
23 | webserver: { | ||
24 | port: 9256 | ||
25 | } | ||
26 | } | ||
27 | // Run server 2 to have transcoding enabled | ||
28 | server = await createSingleServer(2, overrideConfig) | ||
29 | await setAccessTokensToServers([ server ]) | ||
30 | |||
31 | // Upload two videos for our needs | ||
32 | const { uuid: video1UUID } = await server.videos.upload() | ||
33 | await server.videos.upload() | ||
34 | |||
35 | // Create a user | ||
36 | await server.users.create({ username: 'toto', password: 'coucou' }) | ||
37 | |||
38 | // Create channel | ||
39 | const videoChannel = { | ||
40 | name: 'second_channel', | ||
41 | displayName: 'second video channel', | ||
42 | description: 'super video channel description' | ||
43 | } | ||
44 | await server.channels.create({ attributes: videoChannel }) | ||
45 | |||
46 | // Create comments | ||
47 | const text = 'my super first comment' | ||
48 | await server.comments.createThread({ videoId: video1UUID, text }) | ||
49 | |||
50 | await waitJobs(server) | ||
51 | }) | ||
52 | |||
53 | it('Should run update host', async function () { | ||
54 | this.timeout(30000) | ||
55 | |||
56 | await killallServers([ server ]) | ||
57 | // Run server with standard configuration | ||
58 | await server.run() | ||
59 | |||
60 | await server.cli.execWithEnv(`npm run update-host`) | ||
61 | }) | ||
62 | |||
63 | it('Should have updated videos url', async function () { | ||
64 | const { total, data } = await server.videos.list() | ||
65 | expect(total).to.equal(2) | ||
66 | |||
67 | for (const video of data) { | ||
68 | const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) | ||
69 | |||
70 | expect(body.id).to.equal('http://127.0.0.1:9002/videos/watch/' + video.uuid) | ||
71 | |||
72 | const videoDetails = await server.videos.get({ id: video.uuid }) | ||
73 | |||
74 | expect(videoDetails.trackerUrls[0]).to.include(server.host) | ||
75 | expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) | ||
76 | expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host) | ||
77 | } | ||
78 | }) | ||
79 | |||
80 | it('Should have updated video channels url', async function () { | ||
81 | const { data, total } = await server.channels.list({ sort: '-name' }) | ||
82 | expect(total).to.equal(3) | ||
83 | |||
84 | for (const channel of data) { | ||
85 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) | ||
86 | |||
87 | expect(body.id).to.equal('http://127.0.0.1:9002/video-channels/' + channel.name) | ||
88 | } | ||
89 | }) | ||
90 | |||
91 | it('Should have updated accounts url', async function () { | ||
92 | const body = await server.accounts.list() | ||
93 | expect(body.total).to.equal(3) | ||
94 | |||
95 | for (const account of body.data) { | ||
96 | const usernameWithDomain = account.name | ||
97 | const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) | ||
98 | |||
99 | expect(body.id).to.equal('http://127.0.0.1:9002/accounts/' + usernameWithDomain) | ||
100 | } | ||
101 | }) | ||
102 | |||
103 | it('Should have updated torrent hosts', async function () { | ||
104 | this.timeout(30000) | ||
105 | |||
106 | const { data } = await server.videos.list() | ||
107 | expect(data).to.have.lengthOf(2) | ||
108 | |||
109 | for (const video of data) { | ||
110 | const videoDetails = await server.videos.get({ id: video.id }) | ||
111 | const files = getAllFiles(videoDetails) | ||
112 | |||
113 | expect(files).to.have.lengthOf(8) | ||
114 | |||
115 | for (const file of files) { | ||
116 | expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Ftracker%2Fsocket') | ||
117 | expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Fstatic%2F') | ||
118 | |||
119 | const torrent = await parseTorrentVideo(server, file) | ||
120 | const announceWS = torrent.announce.find(a => a === 'ws://127.0.0.1:9002/tracker/socket') | ||
121 | expect(announceWS).to.not.be.undefined | ||
122 | |||
123 | const announceHttp = torrent.announce.find(a => a === 'http://127.0.0.1:9002/tracker/announce') | ||
124 | expect(announceHttp).to.not.be.undefined | ||
125 | |||
126 | expect(torrent.urlList[0]).to.contain('http://127.0.0.1:9002/static/') | ||
127 | } | ||
128 | } | ||
129 | }) | ||
130 | |||
131 | after(async function () { | ||
132 | await cleanupTests([ server ]) | ||
133 | }) | ||
134 | }) | ||