aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/follows.ts9
-rw-r--r--server/tests/api/check-params/index.ts8
-rw-r--r--server/tests/api/check-params/redundancy.ts103
-rw-r--r--server/tests/api/server/index.ts1
-rw-r--r--server/tests/api/server/redundancy.ts140
5 files changed, 249 insertions, 12 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2bc3b27d9..cdc95c81a 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -169,15 +169,6 @@ describe('Test server follows API validators', function () {
169 statusCodeExpected: 404 169 statusCodeExpected: 404
170 }) 170 })
171 }) 171 })
172
173 it('Should succeed with the correct parameters', async function () {
174 await makeDeleteRequest({
175 url: server.url,
176 path: path + '/localhost:9002',
177 token: server.accessToken,
178 statusCodeExpected: 404
179 })
180 })
181 }) 172 })
182 }) 173 })
183 174
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 777acbb0f..44460a167 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -1,15 +1,17 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './accounts' 2import './accounts'
3import './config'
3import './follows' 4import './follows'
4import './jobs' 5import './jobs'
6import './redundancy'
7import './search'
5import './services' 8import './services'
9import './user-subscriptions'
6import './users' 10import './users'
7import './video-abuses' 11import './video-abuses'
8import './video-blacklist' 12import './video-blacklist'
9import './video-captions' 13import './video-captions'
10import './video-channels' 14import './video-channels'
11import './video-comments' 15import './video-comments'
12import './videos'
13import './video-imports' 16import './video-imports'
14import './search' 17import './videos'
15import './user-subscriptions'
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
new file mode 100644
index 000000000..aa588e3dd
--- /dev/null
+++ b/server/tests/api/check-params/redundancy.ts
@@ -0,0 +1,103 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 killallServers,
11 makePutBodyRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 userLogin
15} from '../../utils'
16
17describe('Test server redundancy API validators', function () {
18 let servers: ServerInfo[]
19 let userAccessToken = null
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(30000)
25
26 await flushTests()
27 servers = await flushAndRunMultipleServers(2)
28
29 await setAccessTokensToServers(servers)
30 await doubleFollow(servers[0], servers[1])
31
32 const user = {
33 username: 'user1',
34 password: 'password'
35 }
36
37 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
38 userAccessToken = await userLogin(servers[0], user)
39 })
40
41 describe('When updating redundancy', function () {
42 const path = '/api/v1/server/redundancy'
43
44 it('Should fail with an invalid token', async function () {
45 await makePutBodyRequest({
46 url: servers[0].url,
47 path: path + '/localhost:9002',
48 fields: { redundancyAllowed: true },
49 token: 'fake_token',
50 statusCodeExpected: 401
51 })
52 })
53
54 it('Should fail if the user is not an administrator', async function () {
55 await makePutBodyRequest({
56 url: servers[0].url,
57 path: path + '/localhost:9002',
58 fields: { redundancyAllowed: true },
59 token: userAccessToken,
60 statusCodeExpected: 403
61 })
62 })
63
64 it('Should fail if we do not follow this server', async function () {
65 await makePutBodyRequest({
66 url: servers[0].url,
67 path: path + '/example.com',
68 fields: { redundancyAllowed: true },
69 token: servers[0].accessToken,
70 statusCodeExpected: 404
71 })
72 })
73
74 it('Should fail without de redundancyAllowed param', async function () {
75 await makePutBodyRequest({
76 url: servers[0].url,
77 path: path + '/localhost:9002',
78 fields: { blabla: true },
79 token: servers[0].accessToken,
80 statusCodeExpected: 400
81 })
82 })
83
84 it('Should succeed with the correct parameters', async function () {
85 await makePutBodyRequest({
86 url: servers[0].url,
87 path: path + '/localhost:9002',
88 fields: { redundancyAllowed: true },
89 token: servers[0].accessToken,
90 statusCodeExpected: 204
91 })
92 })
93 })
94
95 after(async function () {
96 killallServers(servers)
97
98 // Keep the logs if the test failed
99 if (this['ok']) {
100 await flushTests()
101 }
102 })
103})
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index eeb8b7a28..c74c68a33 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -3,6 +3,7 @@ import './email'
3import './follows' 3import './follows'
4import './handle-down' 4import './handle-down'
5import './jobs' 5import './jobs'
6import './redundancy'
6import './reverse-proxy' 7import './reverse-proxy'
7import './stats' 8import './stats'
8import './tracker' 9import './tracker'
diff --git a/server/tests/api/server/redundancy.ts b/server/tests/api/server/redundancy.ts
new file mode 100644
index 000000000..c0ec75a45
--- /dev/null
+++ b/server/tests/api/server/redundancy.ts
@@ -0,0 +1,140 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { VideoDetails } from '../../../../shared/models/videos'
6import {
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 getFollowingListPaginationAndSort,
11 getVideo,
12 killallServers,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo,
16 wait,
17 root, viewVideo
18} from '../../utils'
19import { waitJobs } from '../../utils/server/jobs'
20import * as magnetUtil from 'magnet-uri'
21import { updateRedundancy } from '../../utils/server/redundancy'
22import { ActorFollow } from '../../../../shared/models/actors'
23import { readdir } from 'fs-extra'
24import { join } from 'path'
25
26const expect = chai.expect
27
28function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[]) {
29 const parsed = magnetUtil.decode(file.magnetUri)
30
31 for (const ws of baseWebseeds) {
32 const found = parsed.urlList.find(url => url === `${ws}-${file.resolution.id}.mp4`)
33 expect(found, `Webseed ${ws} not found in ${file.magnetUri}`).to.not.be.undefined
34 }
35}
36
37describe('Test videos redundancy', function () {
38 let servers: ServerInfo[] = []
39 let video1Server2UUID: string
40 let video2Server2UUID: string
41
42 before(async function () {
43 this.timeout(120000)
44
45 servers = await flushAndRunMultipleServers(3)
46
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
49
50 {
51 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 server 2' })
52 video1Server2UUID = res.body.video.uuid
53
54 await viewVideo(servers[1].url, video1Server2UUID)
55 }
56
57 {
58 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' })
59 video2Server2UUID = res.body.video.uuid
60 }
61
62 await waitJobs(servers)
63
64 // Server 1 and server 2 follow each other
65 await doubleFollow(servers[0], servers[1])
66 // Server 1 and server 3 follow each other
67 await doubleFollow(servers[0], servers[2])
68 // Server 2 and server 3 follow each other
69 await doubleFollow(servers[1], servers[2])
70
71 await waitJobs(servers)
72 })
73
74 it('Should have 1 webseed on the first video', async function () {
75 const webseeds = [
76 'http://localhost:9002/static/webseed/' + video1Server2UUID
77 ]
78
79 for (const server of servers) {
80 const res = await getVideo(server.url, video1Server2UUID)
81
82 const video: VideoDetails = res.body
83 video.files.forEach(f => checkMagnetWebseeds(f, webseeds))
84 }
85 })
86
87 it('Should enable redundancy on server 1', async function () {
88 await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true)
89
90 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, '-createdAt')
91 const follows: ActorFollow[] = res.body.data
92 const server2 = follows.find(f => f.following.host === 'localhost:9002')
93 const server3 = follows.find(f => f.following.host === 'localhost:9003')
94
95 expect(server3).to.not.be.undefined
96 expect(server3.following.hostRedundancyAllowed).to.be.false
97
98 expect(server2).to.not.be.undefined
99 expect(server2.following.hostRedundancyAllowed).to.be.true
100 })
101
102 it('Should have 2 webseed on the first video', async function () {
103 this.timeout(40000)
104
105 await waitJobs(servers)
106 await wait(15000)
107 await waitJobs(servers)
108
109 const webseeds = [
110 'http://localhost:9001/static/webseed/' + video1Server2UUID,
111 'http://localhost:9002/static/webseed/' + video1Server2UUID
112 ]
113
114 for (const server of servers) {
115 const res = await getVideo(server.url, video1Server2UUID)
116
117 const video: VideoDetails = res.body
118
119 for (const file of video.files) {
120 checkMagnetWebseeds(file, webseeds)
121 }
122 }
123
124 const files = await readdir(join(root(), 'test1', 'videos'))
125 expect(files).to.have.lengthOf(4)
126
127 for (const resolution of [ 240, 360, 480, 720 ]) {
128 expect(files.find(f => f === `${video1Server2UUID}-${resolution}.mp4`)).to.not.be.undefined
129 }
130 })
131
132 after(async function () {
133 killallServers(servers)
134
135 // Keep the logs if the test failed
136 if (this['ok']) {
137 await flushTests()
138 }
139 })
140})