diff options
Diffstat (limited to 'server/tests/api/check-params')
22 files changed, 666 insertions, 109 deletions
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index 9e0b1e35c..68f9519c6 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts | |||
@@ -2,11 +2,15 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { flushTests, killallServers, runServer, ServerInfo } from '../../utils' | 5 | import { flushTests, killallServers, runServer, ServerInfo } from '../../../../shared/utils' |
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 6 | import { |
7 | import { getAccount } from '../../utils/users/accounts' | 7 | checkBadCountPagination, |
8 | 8 | checkBadSortPagination, | |
9 | describe('Test users API validators', function () { | 9 | checkBadStartPagination |
10 | } from '../../../../shared/utils/requests/check-api-params' | ||
11 | import { getAccount } from '../../../../shared/utils/users/accounts' | ||
12 | |||
13 | describe('Test accounts API validators', function () { | ||
10 | const path = '/api/v1/accounts/' | 14 | const path = '/api/v1/accounts/' |
11 | let server: ServerInfo | 15 | let server: ServerInfo |
12 | 16 | ||
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index c745ac975..c20453c16 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts | |||
@@ -13,8 +13,12 @@ import { | |||
13 | makePostBodyRequest, | 13 | makePostBodyRequest, |
14 | ServerInfo, | 14 | ServerInfo, |
15 | setAccessTokensToServers, userLogin | 15 | setAccessTokensToServers, userLogin |
16 | } from '../../utils' | 16 | } from '../../../../shared/utils' |
17 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 17 | import { |
18 | checkBadCountPagination, | ||
19 | checkBadSortPagination, | ||
20 | checkBadStartPagination | ||
21 | } from '../../../../shared/utils/requests/check-api-params' | ||
18 | 22 | ||
19 | describe('Test blocklist API validators', function () { | 23 | describe('Test blocklist API validators', function () { |
20 | let servers: ServerInfo[] | 24 | let servers: ServerInfo[] |
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index d807f910b..4038ecbf0 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -7,7 +7,7 @@ import { CustomConfig } from '../../../../shared/models/server/custom-config.mod | |||
7 | import { | 7 | import { |
8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, | 8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, |
9 | setAccessTokensToServers, userLogin, immutableAssign | 9 | setAccessTokensToServers, userLogin, immutableAssign |
10 | } from '../../utils' | 10 | } from '../../../../shared/utils' |
11 | 11 | ||
12 | describe('Test config API validators', function () { | 12 | describe('Test config API validators', function () { |
13 | const path = '/api/v1/config/custom' | 13 | const path = '/api/v1/config/custom' |
@@ -48,12 +48,16 @@ describe('Test config API validators', function () { | |||
48 | admin: { | 48 | admin: { |
49 | email: 'superadmin1@example.com' | 49 | email: 'superadmin1@example.com' |
50 | }, | 50 | }, |
51 | contactForm: { | ||
52 | enabled: false | ||
53 | }, | ||
51 | user: { | 54 | user: { |
52 | videoQuota: 5242881, | 55 | videoQuota: 5242881, |
53 | videoQuotaDaily: 318742 | 56 | videoQuotaDaily: 318742 |
54 | }, | 57 | }, |
55 | transcoding: { | 58 | transcoding: { |
56 | enabled: true, | 59 | enabled: true, |
60 | allowAdditionalExtensions: true, | ||
57 | threads: 1, | 61 | threads: 1, |
58 | resolutions: { | 62 | resolutions: { |
59 | '240p': false, | 63 | '240p': false, |
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts new file mode 100644 index 000000000..c7e014b1f --- /dev/null +++ b/server/tests/api/check-params/contact-form.ts | |||
@@ -0,0 +1,96 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | flushTests, | ||
7 | immutableAssign, | ||
8 | killallServers, | ||
9 | reRunServer, | ||
10 | runServer, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers | ||
13 | } from '../../../../shared/utils' | ||
14 | import { | ||
15 | checkBadCountPagination, | ||
16 | checkBadSortPagination, | ||
17 | checkBadStartPagination | ||
18 | } from '../../../../shared/utils/requests/check-api-params' | ||
19 | import { getAccount } from '../../../../shared/utils/users/accounts' | ||
20 | import { sendContactForm } from '../../../../shared/utils/server/contact-form' | ||
21 | import { MockSmtpServer } from '../../../../shared/utils/miscs/email' | ||
22 | |||
23 | describe('Test contact form API validators', function () { | ||
24 | let server: ServerInfo | ||
25 | const emails: object[] = [] | ||
26 | const defaultBody = { | ||
27 | fromName: 'super name', | ||
28 | fromEmail: 'toto@example.com', | ||
29 | body: 'Hello, how are you?' | ||
30 | } | ||
31 | |||
32 | // --------------------------------------------------------------- | ||
33 | |||
34 | before(async function () { | ||
35 | this.timeout(60000) | ||
36 | |||
37 | await flushTests() | ||
38 | await MockSmtpServer.Instance.collectEmails(emails) | ||
39 | |||
40 | // Email is disabled | ||
41 | server = await runServer(1) | ||
42 | }) | ||
43 | |||
44 | it('Should not accept a contact form if emails are disabled', async function () { | ||
45 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | ||
46 | }) | ||
47 | |||
48 | it('Should not accept a contact form if it is disabled in the configuration', async function () { | ||
49 | this.timeout(10000) | ||
50 | |||
51 | killallServers([ server ]) | ||
52 | |||
53 | // Contact form is disabled | ||
54 | await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } }) | ||
55 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) | ||
56 | }) | ||
57 | |||
58 | it('Should not accept a contact form if from email is invalid', async function () { | ||
59 | this.timeout(10000) | ||
60 | |||
61 | killallServers([ server ]) | ||
62 | |||
63 | // Email & contact form enabled | ||
64 | await reRunServer(server, { smtp: { hostname: 'localhost' } }) | ||
65 | |||
66 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' })) | ||
67 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' })) | ||
68 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined })) | ||
69 | }) | ||
70 | |||
71 | it('Should not accept a contact form if from name is invalid', async function () { | ||
72 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) })) | ||
73 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' })) | ||
74 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined })) | ||
75 | }) | ||
76 | |||
77 | it('Should not accept a contact form if body is invalid', async function () { | ||
78 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) })) | ||
79 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' })) | ||
80 | await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined })) | ||
81 | }) | ||
82 | |||
83 | it('Should accept a contact form with the correct parameters', async function () { | ||
84 | await sendContactForm(immutableAssign(defaultBody, { url: server.url })) | ||
85 | }) | ||
86 | |||
87 | after(async function () { | ||
88 | MockSmtpServer.Instance.kill() | ||
89 | killallServers([ server ]) | ||
90 | |||
91 | // Keep the logs if the test failed | ||
92 | if (this['ok']) { | ||
93 | await flushTests() | ||
94 | } | ||
95 | }) | ||
96 | }) | ||
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index cdc95c81a..2ad1575a3 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts | |||
@@ -5,8 +5,12 @@ import 'mocha' | |||
5 | import { | 5 | import { |
6 | createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | 6 | createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, |
7 | userLogin | 7 | userLogin |
8 | } from '../../utils' | 8 | } from '../../../../shared/utils' |
9 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 9 | import { |
10 | checkBadCountPagination, | ||
11 | checkBadSortPagination, | ||
12 | checkBadStartPagination | ||
13 | } from '../../../../shared/utils/requests/check-api-params' | ||
10 | 14 | ||
11 | describe('Test server follows API validators', function () { | 15 | describe('Test server follows API validators', function () { |
12 | let server: ServerInfo | 16 | let server: ServerInfo |
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 877ceb0a7..77c17036a 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './accounts' | 1 | import './accounts' |
3 | import './blocklist' | 2 | import './blocklist' |
4 | import './config' | 3 | import './config' |
4 | import './contact-form' | ||
5 | import './follows' | 5 | import './follows' |
6 | import './jobs' | 6 | import './jobs' |
7 | import './redundancy' | 7 | import './redundancy' |
8 | import './search' | 8 | import './search' |
9 | import './services' | 9 | import './services' |
10 | import './user-notifications' | ||
10 | import './user-subscriptions' | 11 | import './user-subscriptions' |
11 | import './users' | 12 | import './users' |
12 | import './video-abuses' | 13 | import './video-abuses' |
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index ce3ac8809..89760ff98 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts | |||
@@ -2,9 +2,21 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { createUser, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils' | 5 | import { |
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 6 | createUser, |
7 | import { makeGetRequest } from '../../utils/requests/requests' | 7 | flushTests, |
8 | killallServers, | ||
9 | runServer, | ||
10 | ServerInfo, | ||
11 | setAccessTokensToServers, | ||
12 | userLogin | ||
13 | } from '../../../../shared/utils' | ||
14 | import { | ||
15 | checkBadCountPagination, | ||
16 | checkBadSortPagination, | ||
17 | checkBadStartPagination | ||
18 | } from '../../../../shared/utils/requests/check-api-params' | ||
19 | import { makeGetRequest } from '../../../../shared/utils/requests/requests' | ||
8 | 20 | ||
9 | describe('Test jobs API validators', function () { | 21 | describe('Test jobs API validators', function () { |
10 | const path = '/api/v1/jobs/failed' | 22 | const path = '/api/v1/jobs/failed' |
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index aa588e3dd..ff4726ceb 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts | |||
@@ -12,7 +12,7 @@ import { | |||
12 | ServerInfo, | 12 | ServerInfo, |
13 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
14 | userLogin | 14 | userLogin |
15 | } from '../../utils' | 15 | } from '../../../../shared/utils' |
16 | 16 | ||
17 | describe('Test server redundancy API validators', function () { | 17 | describe('Test server redundancy API validators', function () { |
18 | let servers: ServerInfo[] | 18 | let servers: ServerInfo[] |
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index eabf602ac..aa81965f3 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts | |||
@@ -2,8 +2,12 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils' | 5 | import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils' |
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 6 | import { |
7 | checkBadCountPagination, | ||
8 | checkBadSortPagination, | ||
9 | checkBadStartPagination | ||
10 | } from '../../../../shared/utils/requests/check-api-params' | ||
7 | 11 | ||
8 | describe('Test videos API validator', function () { | 12 | describe('Test videos API validator', function () { |
9 | let server: ServerInfo | 13 | let server: ServerInfo |
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index fcde7e179..28591af9d 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts | |||
@@ -2,7 +2,15 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' | 5 | import { |
6 | flushTests, | ||
7 | killallServers, | ||
8 | makeGetRequest, | ||
9 | runServer, | ||
10 | ServerInfo, | ||
11 | setAccessTokensToServers, | ||
12 | uploadVideo | ||
13 | } from '../../../../shared/utils' | ||
6 | 14 | ||
7 | describe('Test services API validators', function () { | 15 | describe('Test services API validators', function () { |
8 | let server: ServerInfo | 16 | let server: ServerInfo |
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts new file mode 100644 index 000000000..714f481e9 --- /dev/null +++ b/server/tests/api/check-params/user-notifications.ts | |||
@@ -0,0 +1,297 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as io from 'socket.io-client' | ||
5 | |||
6 | import { | ||
7 | flushTests, | ||
8 | immutableAssign, | ||
9 | killallServers, | ||
10 | makeGetRequest, | ||
11 | makePostBodyRequest, | ||
12 | makePutBodyRequest, | ||
13 | runServer, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers, | ||
16 | wait | ||
17 | } from '../../../../shared/utils' | ||
18 | import { | ||
19 | checkBadCountPagination, | ||
20 | checkBadSortPagination, | ||
21 | checkBadStartPagination | ||
22 | } from '../../../../shared/utils/requests/check-api-params' | ||
23 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' | ||
24 | |||
25 | describe('Test user notifications API validators', function () { | ||
26 | let server: ServerInfo | ||
27 | |||
28 | // --------------------------------------------------------------- | ||
29 | |||
30 | before(async function () { | ||
31 | this.timeout(30000) | ||
32 | |||
33 | await flushTests() | ||
34 | |||
35 | server = await runServer(1) | ||
36 | |||
37 | await setAccessTokensToServers([ server ]) | ||
38 | }) | ||
39 | |||
40 | describe('When listing my notifications', function () { | ||
41 | const path = '/api/v1/users/me/notifications' | ||
42 | |||
43 | it('Should fail with a bad start pagination', async function () { | ||
44 | await checkBadStartPagination(server.url, path, server.accessToken) | ||
45 | }) | ||
46 | |||
47 | it('Should fail with a bad count pagination', async function () { | ||
48 | await checkBadCountPagination(server.url, path, server.accessToken) | ||
49 | }) | ||
50 | |||
51 | it('Should fail with an incorrect sort', async function () { | ||
52 | await checkBadSortPagination(server.url, path, server.accessToken) | ||
53 | }) | ||
54 | |||
55 | it('Should fail with an incorrect unread parameter', async function () { | ||
56 | await makeGetRequest({ | ||
57 | url: server.url, | ||
58 | path, | ||
59 | query: { | ||
60 | unread: 'toto' | ||
61 | }, | ||
62 | token: server.accessToken, | ||
63 | statusCodeExpected: 200 | ||
64 | }) | ||
65 | }) | ||
66 | |||
67 | it('Should fail with a non authenticated user', async function () { | ||
68 | await makeGetRequest({ | ||
69 | url: server.url, | ||
70 | path, | ||
71 | statusCodeExpected: 401 | ||
72 | }) | ||
73 | }) | ||
74 | |||
75 | it('Should succeed with the correct parameters', async function () { | ||
76 | await makeGetRequest({ | ||
77 | url: server.url, | ||
78 | path, | ||
79 | token: server.accessToken, | ||
80 | statusCodeExpected: 200 | ||
81 | }) | ||
82 | }) | ||
83 | }) | ||
84 | |||
85 | describe('When marking as read my notifications', function () { | ||
86 | const path = '/api/v1/users/me/notifications/read' | ||
87 | |||
88 | it('Should fail with wrong ids parameters', async function () { | ||
89 | await makePostBodyRequest({ | ||
90 | url: server.url, | ||
91 | path, | ||
92 | fields: { | ||
93 | ids: [ 'hello' ] | ||
94 | }, | ||
95 | token: server.accessToken, | ||
96 | statusCodeExpected: 400 | ||
97 | }) | ||
98 | |||
99 | await makePostBodyRequest({ | ||
100 | url: server.url, | ||
101 | path, | ||
102 | fields: { | ||
103 | ids: [ ] | ||
104 | }, | ||
105 | token: server.accessToken, | ||
106 | statusCodeExpected: 400 | ||
107 | }) | ||
108 | |||
109 | await makePostBodyRequest({ | ||
110 | url: server.url, | ||
111 | path, | ||
112 | fields: { | ||
113 | ids: 5 | ||
114 | }, | ||
115 | token: server.accessToken, | ||
116 | statusCodeExpected: 400 | ||
117 | }) | ||
118 | }) | ||
119 | |||
120 | it('Should fail with a non authenticated user', async function () { | ||
121 | await makePostBodyRequest({ | ||
122 | url: server.url, | ||
123 | path, | ||
124 | fields: { | ||
125 | ids: [ 5 ] | ||
126 | }, | ||
127 | statusCodeExpected: 401 | ||
128 | }) | ||
129 | }) | ||
130 | |||
131 | it('Should succeed with the correct parameters', async function () { | ||
132 | await makePostBodyRequest({ | ||
133 | url: server.url, | ||
134 | path, | ||
135 | fields: { | ||
136 | ids: [ 5 ] | ||
137 | }, | ||
138 | token: server.accessToken, | ||
139 | statusCodeExpected: 204 | ||
140 | }) | ||
141 | }) | ||
142 | }) | ||
143 | |||
144 | describe('When marking as read my notifications', function () { | ||
145 | const path = '/api/v1/users/me/notifications/read-all' | ||
146 | |||
147 | it('Should fail with a non authenticated user', async function () { | ||
148 | await makePostBodyRequest({ | ||
149 | url: server.url, | ||
150 | path, | ||
151 | statusCodeExpected: 401 | ||
152 | }) | ||
153 | }) | ||
154 | |||
155 | it('Should succeed with the correct parameters', async function () { | ||
156 | await makePostBodyRequest({ | ||
157 | url: server.url, | ||
158 | path, | ||
159 | token: server.accessToken, | ||
160 | statusCodeExpected: 204 | ||
161 | }) | ||
162 | }) | ||
163 | }) | ||
164 | |||
165 | describe('When updating my notification settings', function () { | ||
166 | const path = '/api/v1/users/me/notification-settings' | ||
167 | const correctFields: UserNotificationSetting = { | ||
168 | newVideoFromSubscription: UserNotificationSettingValue.WEB, | ||
169 | newCommentOnMyVideo: UserNotificationSettingValue.WEB, | ||
170 | videoAbuseAsModerator: UserNotificationSettingValue.WEB, | ||
171 | blacklistOnMyVideo: UserNotificationSettingValue.WEB, | ||
172 | myVideoImportFinished: UserNotificationSettingValue.WEB, | ||
173 | myVideoPublished: UserNotificationSettingValue.WEB, | ||
174 | commentMention: UserNotificationSettingValue.WEB, | ||
175 | newFollow: UserNotificationSettingValue.WEB, | ||
176 | newUserRegistration: UserNotificationSettingValue.WEB | ||
177 | } | ||
178 | |||
179 | it('Should fail with missing fields', async function () { | ||
180 | await makePutBodyRequest({ | ||
181 | url: server.url, | ||
182 | path, | ||
183 | token: server.accessToken, | ||
184 | fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, | ||
185 | statusCodeExpected: 400 | ||
186 | }) | ||
187 | }) | ||
188 | |||
189 | it('Should fail with incorrect field values', async function () { | ||
190 | { | ||
191 | const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) | ||
192 | |||
193 | await makePutBodyRequest({ | ||
194 | url: server.url, | ||
195 | path, | ||
196 | token: server.accessToken, | ||
197 | fields, | ||
198 | statusCodeExpected: 400 | ||
199 | }) | ||
200 | } | ||
201 | |||
202 | { | ||
203 | const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) | ||
204 | |||
205 | await makePutBodyRequest({ | ||
206 | url: server.url, | ||
207 | path, | ||
208 | fields, | ||
209 | token: server.accessToken, | ||
210 | statusCodeExpected: 400 | ||
211 | }) | ||
212 | } | ||
213 | }) | ||
214 | |||
215 | it('Should fail with a non authenticated user', async function () { | ||
216 | await makePutBodyRequest({ | ||
217 | url: server.url, | ||
218 | path, | ||
219 | fields: correctFields, | ||
220 | statusCodeExpected: 401 | ||
221 | }) | ||
222 | }) | ||
223 | |||
224 | it('Should succeed with the correct parameters', async function () { | ||
225 | await makePutBodyRequest({ | ||
226 | url: server.url, | ||
227 | path, | ||
228 | token: server.accessToken, | ||
229 | fields: correctFields, | ||
230 | statusCodeExpected: 204 | ||
231 | }) | ||
232 | }) | ||
233 | }) | ||
234 | |||
235 | describe('When connecting to my notification socket', function () { | ||
236 | it('Should fail with no token', function (next) { | ||
237 | const socket = io('http://localhost:9001/user-notifications', { reconnection: false }) | ||
238 | |||
239 | socket.on('error', () => { | ||
240 | socket.removeListener('error', this) | ||
241 | socket.disconnect() | ||
242 | next() | ||
243 | }) | ||
244 | |||
245 | socket.on('connect', () => { | ||
246 | socket.disconnect() | ||
247 | next(new Error('Connected with a missing token.')) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | it('Should fail with an invalid token', function (next) { | ||
252 | const socket = io('http://localhost:9001/user-notifications', { | ||
253 | query: { accessToken: 'bad_access_token' }, | ||
254 | reconnection: false | ||
255 | }) | ||
256 | |||
257 | socket.on('error', () => { | ||
258 | socket.removeListener('error', this) | ||
259 | socket.disconnect() | ||
260 | next() | ||
261 | }) | ||
262 | |||
263 | socket.on('connect', () => { | ||
264 | socket.disconnect() | ||
265 | next(new Error('Connected with an invalid token.')) | ||
266 | }) | ||
267 | }) | ||
268 | |||
269 | it('Should success with the correct token', function (next) { | ||
270 | const socket = io('http://localhost:9001/user-notifications', { | ||
271 | query: { accessToken: server.accessToken }, | ||
272 | reconnection: false | ||
273 | }) | ||
274 | |||
275 | const errorListener = socket.on('error', err => { | ||
276 | next(new Error('Error in connection: ' + err)) | ||
277 | }) | ||
278 | |||
279 | socket.on('connect', async () => { | ||
280 | socket.removeListener('error', errorListener) | ||
281 | socket.disconnect() | ||
282 | |||
283 | await wait(500) | ||
284 | next() | ||
285 | }) | ||
286 | }) | ||
287 | }) | ||
288 | |||
289 | after(async function () { | ||
290 | killallServers([ server ]) | ||
291 | |||
292 | // Keep the logs if the test failed | ||
293 | if (this['ok']) { | ||
294 | await flushTests() | ||
295 | } | ||
296 | }) | ||
297 | }) | ||
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 6af7ed43b..8a9ced7c1 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts | |||
@@ -13,9 +13,14 @@ import { | |||
13 | ServerInfo, | 13 | ServerInfo, |
14 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
15 | userLogin | 15 | userLogin |
16 | } from '../../utils' | 16 | } from '../../../../shared/utils' |
17 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 17 | |
18 | import { waitJobs } from '../../utils/server/jobs' | 18 | import { |
19 | checkBadCountPagination, | ||
20 | checkBadSortPagination, | ||
21 | checkBadStartPagination | ||
22 | } from '../../../../shared/utils/requests/check-api-params' | ||
23 | import { waitJobs } from '../../../../shared/utils/server/jobs' | ||
19 | 24 | ||
20 | describe('Test user subscriptions API validators', function () { | 25 | describe('Test user subscriptions API validators', function () { |
21 | const path = '/api/v1/users/me/subscriptions' | 26 | const path = '/api/v1/users/me/subscriptions' |
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 273be1679..a3e8e2e9c 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -9,11 +9,15 @@ import { | |||
9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, | 9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, |
10 | makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, | 10 | makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, |
11 | updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser | 11 | updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser |
12 | } from '../../utils' | 12 | } from '../../../../shared/utils' |
13 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 13 | import { |
14 | import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' | 14 | checkBadCountPagination, |
15 | checkBadSortPagination, | ||
16 | checkBadStartPagination | ||
17 | } from '../../../../shared/utils/requests/check-api-params' | ||
18 | import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' | ||
15 | import { VideoPrivacy } from '../../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../../shared/models/videos' |
16 | import { waitJobs } from '../../utils/server/jobs' | 20 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
17 | import { expect } from 'chai' | 21 | import { expect } from 'chai' |
18 | 22 | ||
19 | describe('Test users API validators', function () { | 23 | describe('Test users API validators', function () { |
@@ -99,13 +103,13 @@ describe('Test users API validators', function () { | |||
99 | } | 103 | } |
100 | 104 | ||
101 | it('Should fail with a too small username', async function () { | 105 | it('Should fail with a too small username', async function () { |
102 | const fields = immutableAssign(baseCorrectParams, { username: 'fi' }) | 106 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
103 | 107 | ||
104 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 108 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
105 | }) | 109 | }) |
106 | 110 | ||
107 | it('Should fail with a too long username', async function () { | 111 | it('Should fail with a too long username', async function () { |
108 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 112 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
109 | 113 | ||
110 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
111 | }) | 115 | }) |
@@ -304,6 +308,14 @@ describe('Test users API validators', function () { | |||
304 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 308 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
305 | }) | 309 | }) |
306 | 310 | ||
311 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { | ||
312 | const fields = { | ||
313 | videosHistoryEnabled: -1 | ||
314 | } | ||
315 | |||
316 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | ||
317 | }) | ||
318 | |||
307 | it('Should fail with an non authenticated user', async function () { | 319 | it('Should fail with an non authenticated user', async function () { |
308 | const fields = { | 320 | const fields = { |
309 | currentPassword: 'my super password', | 321 | currentPassword: 'my super password', |
@@ -473,11 +485,10 @@ describe('Test users API validators', function () { | |||
473 | email: 'email@example.com', | 485 | email: 'email@example.com', |
474 | emailVerified: true, | 486 | emailVerified: true, |
475 | videoQuota: 42, | 487 | videoQuota: 42, |
476 | role: UserRole.MODERATOR | 488 | role: UserRole.USER |
477 | } | 489 | } |
478 | 490 | ||
479 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | 491 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) |
480 | userAccessToken = await userLogin(server, user) | ||
481 | }) | 492 | }) |
482 | }) | 493 | }) |
483 | 494 | ||
@@ -550,13 +561,13 @@ describe('Test users API validators', function () { | |||
550 | } | 561 | } |
551 | 562 | ||
552 | it('Should fail with a too small username', async function () { | 563 | it('Should fail with a too small username', async function () { |
553 | const fields = immutableAssign(baseCorrectParams, { username: 'ji' }) | 564 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
554 | 565 | ||
555 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 566 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
556 | }) | 567 | }) |
557 | 568 | ||
558 | it('Should fail with a too long username', async function () { | 569 | it('Should fail with a too long username', async function () { |
559 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 570 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
560 | 571 | ||
561 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 572 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
562 | }) | 573 | }) |
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index d2bed6a2a..3b8f5f14d 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts | |||
@@ -15,8 +15,12 @@ import { | |||
15 | updateVideoAbuse, | 15 | updateVideoAbuse, |
16 | uploadVideo, | 16 | uploadVideo, |
17 | userLogin | 17 | userLogin |
18 | } from '../../utils' | 18 | } from '../../../../shared/utils' |
19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 19 | import { |
20 | checkBadCountPagination, | ||
21 | checkBadSortPagination, | ||
22 | checkBadStartPagination | ||
23 | } from '../../../../shared/utils/requests/check-api-params' | ||
20 | import { VideoAbuseState } from '../../../../shared/models/videos' | 24 | import { VideoAbuseState } from '../../../../shared/models/videos' |
21 | 25 | ||
22 | describe('Test video abuses API validators', function () { | 26 | describe('Test video abuses API validators', function () { |
@@ -109,8 +113,8 @@ describe('Test video abuses API validators', function () { | |||
109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 113 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
110 | }) | 114 | }) |
111 | 115 | ||
112 | it('Should fail with a reason too big', async function () { | 116 | it('Should fail with a too big reason', async function () { |
113 | const fields = { reason: 'super'.repeat(61) } | 117 | const fields = { reason: 'super'.repeat(605) } |
114 | 118 | ||
115 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 119 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
116 | }) | 120 | }) |
@@ -150,7 +154,7 @@ describe('Test video abuses API validators', function () { | |||
150 | }) | 154 | }) |
151 | 155 | ||
152 | it('Should fail with a bad moderation comment', async function () { | 156 | it('Should fail with a bad moderation comment', async function () { |
153 | const body = { moderationComment: 'b'.repeat(305) } | 157 | const body = { moderationComment: 'b'.repeat(3001) } |
154 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400) | 158 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400) |
155 | }) | 159 | }) |
156 | 160 | ||
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 473216236..6b82643f4 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -4,25 +4,33 @@ import 'mocha' | |||
4 | 4 | ||
5 | import { | 5 | import { |
6 | createUser, | 6 | createUser, |
7 | doubleFollow, | ||
8 | flushAndRunMultipleServers, | ||
7 | flushTests, | 9 | flushTests, |
8 | getBlacklistedVideosList, getVideo, getVideoWithToken, | 10 | getBlacklistedVideosList, |
11 | getVideo, | ||
12 | getVideoWithToken, | ||
9 | killallServers, | 13 | killallServers, |
10 | makePostBodyRequest, | 14 | makePostBodyRequest, |
11 | makePutBodyRequest, | 15 | makePutBodyRequest, |
12 | removeVideoFromBlacklist, | 16 | removeVideoFromBlacklist, |
13 | runServer, | ||
14 | ServerInfo, | 17 | ServerInfo, |
15 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
16 | uploadVideo, | 19 | uploadVideo, |
17 | userLogin | 20 | userLogin, waitJobs |
18 | } from '../../utils' | 21 | } from '../../../../shared/utils' |
19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 22 | import { |
23 | checkBadCountPagination, | ||
24 | checkBadSortPagination, | ||
25 | checkBadStartPagination | ||
26 | } from '../../../../shared/utils/requests/check-api-params' | ||
20 | import { VideoDetails } from '../../../../shared/models/videos' | 27 | import { VideoDetails } from '../../../../shared/models/videos' |
21 | import { expect } from 'chai' | 28 | import { expect } from 'chai' |
22 | 29 | ||
23 | describe('Test video blacklist API validators', function () { | 30 | describe('Test video blacklist API validators', function () { |
24 | let server: ServerInfo | 31 | let servers: ServerInfo[] |
25 | let notBlacklistedVideoId: number | 32 | let notBlacklistedVideoId: number |
33 | let remoteVideoUUID: string | ||
26 | let userAccessToken1 = '' | 34 | let userAccessToken1 = '' |
27 | let userAccessToken2 = '' | 35 | let userAccessToken2 = '' |
28 | 36 | ||
@@ -32,75 +40,89 @@ describe('Test video blacklist API validators', function () { | |||
32 | this.timeout(120000) | 40 | this.timeout(120000) |
33 | 41 | ||
34 | await flushTests() | 42 | await flushTests() |
43 | servers = await flushAndRunMultipleServers(2) | ||
35 | 44 | ||
36 | server = await runServer(1) | 45 | await setAccessTokensToServers(servers) |
37 | 46 | await doubleFollow(servers[0], servers[1]) | |
38 | await setAccessTokensToServers([ server ]) | ||
39 | 47 | ||
40 | { | 48 | { |
41 | const username = 'user1' | 49 | const username = 'user1' |
42 | const password = 'my super password' | 50 | const password = 'my super password' |
43 | await createUser(server.url, server.accessToken, username, password) | 51 | await createUser(servers[0].url, servers[0].accessToken, username, password) |
44 | userAccessToken1 = await userLogin(server, { username, password }) | 52 | userAccessToken1 = await userLogin(servers[0], { username, password }) |
45 | } | 53 | } |
46 | 54 | ||
47 | { | 55 | { |
48 | const username = 'user2' | 56 | const username = 'user2' |
49 | const password = 'my super password' | 57 | const password = 'my super password' |
50 | await createUser(server.url, server.accessToken, username, password) | 58 | await createUser(servers[0].url, servers[0].accessToken, username, password) |
51 | userAccessToken2 = await userLogin(server, { username, password }) | 59 | userAccessToken2 = await userLogin(servers[0], { username, password }) |
52 | } | 60 | } |
53 | 61 | ||
54 | { | 62 | { |
55 | const res = await uploadVideo(server.url, userAccessToken1, {}) | 63 | const res = await uploadVideo(servers[0].url, userAccessToken1, {}) |
56 | server.video = res.body.video | 64 | servers[0].video = res.body.video |
57 | } | 65 | } |
58 | 66 | ||
59 | { | 67 | { |
60 | const res = await uploadVideo(server.url, server.accessToken, {}) | 68 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) |
61 | notBlacklistedVideoId = res.body.video.uuid | 69 | notBlacklistedVideoId = res.body.video.uuid |
62 | } | 70 | } |
71 | |||
72 | { | ||
73 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) | ||
74 | remoteVideoUUID = res.body.video.uuid | ||
75 | } | ||
76 | |||
77 | await waitJobs(servers) | ||
63 | }) | 78 | }) |
64 | 79 | ||
65 | describe('When adding a video in blacklist', function () { | 80 | describe('When adding a video in blacklist', function () { |
66 | const basePath = '/api/v1/videos/' | 81 | const basePath = '/api/v1/videos/' |
67 | 82 | ||
68 | it('Should fail with nothing', async function () { | 83 | it('Should fail with nothing', async function () { |
69 | const path = basePath + server.video + '/blacklist' | 84 | const path = basePath + servers[0].video + '/blacklist' |
70 | const fields = {} | 85 | const fields = {} |
71 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 86 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
72 | }) | 87 | }) |
73 | 88 | ||
74 | it('Should fail with a wrong video', async function () { | 89 | it('Should fail with a wrong video', async function () { |
75 | const wrongPath = '/api/v1/videos/blabla/blacklist' | 90 | const wrongPath = '/api/v1/videos/blabla/blacklist' |
76 | const fields = {} | 91 | const fields = {} |
77 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | 92 | await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields }) |
78 | }) | 93 | }) |
79 | 94 | ||
80 | it('Should fail with a non authenticated user', async function () { | 95 | it('Should fail with a non authenticated user', async function () { |
81 | const path = basePath + server.video + '/blacklist' | 96 | const path = basePath + servers[0].video + '/blacklist' |
82 | const fields = {} | 97 | const fields = {} |
83 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | 98 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
84 | }) | 99 | }) |
85 | 100 | ||
86 | it('Should fail with a non admin user', async function () { | 101 | it('Should fail with a non admin user', async function () { |
87 | const path = basePath + server.video + '/blacklist' | 102 | const path = basePath + servers[0].video + '/blacklist' |
88 | const fields = {} | 103 | const fields = {} |
89 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) | 104 | await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
90 | }) | 105 | }) |
91 | 106 | ||
92 | it('Should fail with an invalid reason', async function () { | 107 | it('Should fail with an invalid reason', async function () { |
93 | const path = basePath + server.video.uuid + '/blacklist' | 108 | const path = basePath + servers[0].video.uuid + '/blacklist' |
94 | const fields = { reason: 'a'.repeat(305) } | 109 | const fields = { reason: 'a'.repeat(305) } |
95 | 110 | ||
96 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 111 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
112 | }) | ||
113 | |||
114 | it('Should fail to unfederate a remote video', async function () { | ||
115 | const path = basePath + remoteVideoUUID + '/blacklist' | ||
116 | const fields = { unfederate: true } | ||
117 | |||
118 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) | ||
97 | }) | 119 | }) |
98 | 120 | ||
99 | it('Should succeed with the correct params', async function () { | 121 | it('Should succeed with the correct params', async function () { |
100 | const path = basePath + server.video.uuid + '/blacklist' | 122 | const path = basePath + servers[0].video.uuid + '/blacklist' |
101 | const fields = { } | 123 | const fields = { } |
102 | 124 | ||
103 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | 125 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) |
104 | }) | 126 | }) |
105 | }) | 127 | }) |
106 | 128 | ||
@@ -110,61 +132,61 @@ describe('Test video blacklist API validators', function () { | |||
110 | it('Should fail with a wrong video', async function () { | 132 | it('Should fail with a wrong video', async function () { |
111 | const wrongPath = '/api/v1/videos/blabla/blacklist' | 133 | const wrongPath = '/api/v1/videos/blabla/blacklist' |
112 | const fields = {} | 134 | const fields = {} |
113 | await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | 135 | await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields }) |
114 | }) | 136 | }) |
115 | 137 | ||
116 | it('Should fail with a video not blacklisted', async function () { | 138 | it('Should fail with a video not blacklisted', async function () { |
117 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' | 139 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' |
118 | const fields = {} | 140 | const fields = {} |
119 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | 141 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) |
120 | }) | 142 | }) |
121 | 143 | ||
122 | it('Should fail with a non authenticated user', async function () { | 144 | it('Should fail with a non authenticated user', async function () { |
123 | const path = basePath + server.video + '/blacklist' | 145 | const path = basePath + servers[0].video + '/blacklist' |
124 | const fields = {} | 146 | const fields = {} |
125 | await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | 147 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
126 | }) | 148 | }) |
127 | 149 | ||
128 | it('Should fail with a non admin user', async function () { | 150 | it('Should fail with a non admin user', async function () { |
129 | const path = basePath + server.video + '/blacklist' | 151 | const path = basePath + servers[0].video + '/blacklist' |
130 | const fields = {} | 152 | const fields = {} |
131 | await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) | 153 | await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
132 | }) | 154 | }) |
133 | 155 | ||
134 | it('Should fail with an invalid reason', async function () { | 156 | it('Should fail with an invalid reason', async function () { |
135 | const path = basePath + server.video.uuid + '/blacklist' | 157 | const path = basePath + servers[0].video.uuid + '/blacklist' |
136 | const fields = { reason: 'a'.repeat(305) } | 158 | const fields = { reason: 'a'.repeat(305) } |
137 | 159 | ||
138 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 160 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
139 | }) | 161 | }) |
140 | 162 | ||
141 | it('Should succeed with the correct params', async function () { | 163 | it('Should succeed with the correct params', async function () { |
142 | const path = basePath + server.video.uuid + '/blacklist' | 164 | const path = basePath + servers[0].video.uuid + '/blacklist' |
143 | const fields = { reason: 'hello' } | 165 | const fields = { reason: 'hello' } |
144 | 166 | ||
145 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | 167 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) |
146 | }) | 168 | }) |
147 | }) | 169 | }) |
148 | 170 | ||
149 | describe('When getting blacklisted video', function () { | 171 | describe('When getting blacklisted video', function () { |
150 | 172 | ||
151 | it('Should fail with a non authenticated user', async function () { | 173 | it('Should fail with a non authenticated user', async function () { |
152 | await getVideo(server.url, server.video.uuid, 401) | 174 | await getVideo(servers[0].url, servers[0].video.uuid, 401) |
153 | }) | 175 | }) |
154 | 176 | ||
155 | it('Should fail with another user', async function () { | 177 | it('Should fail with another user', async function () { |
156 | await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403) | 178 | await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) |
157 | }) | 179 | }) |
158 | 180 | ||
159 | it('Should succeed with the owner authenticated user', async function () { | 181 | it('Should succeed with the owner authenticated user', async function () { |
160 | const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200) | 182 | const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) |
161 | const video: VideoDetails = res.body | 183 | const video: VideoDetails = res.body |
162 | 184 | ||
163 | expect(video.blacklisted).to.be.true | 185 | expect(video.blacklisted).to.be.true |
164 | }) | 186 | }) |
165 | 187 | ||
166 | it('Should succeed with an admin', async function () { | 188 | it('Should succeed with an admin', async function () { |
167 | const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200) | 189 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) |
168 | const video: VideoDetails = res.body | 190 | const video: VideoDetails = res.body |
169 | 191 | ||
170 | expect(video.blacklisted).to.be.true | 192 | expect(video.blacklisted).to.be.true |
@@ -173,24 +195,24 @@ describe('Test video blacklist API validators', function () { | |||
173 | 195 | ||
174 | describe('When removing a video in blacklist', function () { | 196 | describe('When removing a video in blacklist', function () { |
175 | it('Should fail with a non authenticated user', async function () { | 197 | it('Should fail with a non authenticated user', async function () { |
176 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) | 198 | await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) |
177 | }) | 199 | }) |
178 | 200 | ||
179 | it('Should fail with a non admin user', async function () { | 201 | it('Should fail with a non admin user', async function () { |
180 | await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403) | 202 | await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) |
181 | }) | 203 | }) |
182 | 204 | ||
183 | it('Should fail with an incorrect id', async function () { | 205 | it('Should fail with an incorrect id', async function () { |
184 | await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) | 206 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) |
185 | }) | 207 | }) |
186 | 208 | ||
187 | it('Should fail with a not blacklisted video', async function () { | 209 | it('Should fail with a not blacklisted video', async function () { |
188 | // The video was not added to the blacklist so it should fail | 210 | // The video was not added to the blacklist so it should fail |
189 | await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404) | 211 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) |
190 | }) | 212 | }) |
191 | 213 | ||
192 | it('Should succeed with the correct params', async function () { | 214 | it('Should succeed with the correct params', async function () { |
193 | await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204) | 215 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) |
194 | }) | 216 | }) |
195 | }) | 217 | }) |
196 | 218 | ||
@@ -198,28 +220,28 @@ describe('Test video blacklist API validators', function () { | |||
198 | const basePath = '/api/v1/videos/blacklist/' | 220 | const basePath = '/api/v1/videos/blacklist/' |
199 | 221 | ||
200 | it('Should fail with a non authenticated user', async function () { | 222 | it('Should fail with a non authenticated user', async function () { |
201 | await getBlacklistedVideosList(server.url, 'fake token', 401) | 223 | await getBlacklistedVideosList(servers[0].url, 'fake token', 401) |
202 | }) | 224 | }) |
203 | 225 | ||
204 | it('Should fail with a non admin user', async function () { | 226 | it('Should fail with a non admin user', async function () { |
205 | await getBlacklistedVideosList(server.url, userAccessToken2, 403) | 227 | await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403) |
206 | }) | 228 | }) |
207 | 229 | ||
208 | it('Should fail with a bad start pagination', async function () { | 230 | it('Should fail with a bad start pagination', async function () { |
209 | await checkBadStartPagination(server.url, basePath, server.accessToken) | 231 | await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken) |
210 | }) | 232 | }) |
211 | 233 | ||
212 | it('Should fail with a bad count pagination', async function () { | 234 | it('Should fail with a bad count pagination', async function () { |
213 | await checkBadCountPagination(server.url, basePath, server.accessToken) | 235 | await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken) |
214 | }) | 236 | }) |
215 | 237 | ||
216 | it('Should fail with an incorrect sort', async function () { | 238 | it('Should fail with an incorrect sort', async function () { |
217 | await checkBadSortPagination(server.url, basePath, server.accessToken) | 239 | await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken) |
218 | }) | 240 | }) |
219 | }) | 241 | }) |
220 | 242 | ||
221 | after(async function () { | 243 | after(async function () { |
222 | killallServers([ server ]) | 244 | killallServers(servers) |
223 | 245 | ||
224 | // Keep the logs if the test failed | 246 | // Keep the logs if the test failed |
225 | if (this['ok']) { | 247 | if (this['ok']) { |
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 8d46971a1..e4d36fd4f 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts | |||
@@ -13,9 +13,9 @@ import { | |||
13 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
14 | uploadVideo, | 14 | uploadVideo, |
15 | userLogin | 15 | userLogin |
16 | } from '../../utils' | 16 | } from '../../../../shared/utils' |
17 | import { join } from 'path' | 17 | import { join } from 'path' |
18 | import { createVideoCaption } from '../../utils/videos/video-captions' | 18 | import { createVideoCaption } from '../../../../shared/utils/videos/video-captions' |
19 | 19 | ||
20 | describe('Test video captions API validator', function () { | 20 | describe('Test video captions API validator', function () { |
21 | const path = '/api/v1/videos/' | 21 | const path = '/api/v1/videos/' |
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index e5696224d..14e4deaf7 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts | |||
@@ -20,8 +20,12 @@ import { | |||
20 | ServerInfo, | 20 | ServerInfo, |
21 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
22 | userLogin | 22 | userLogin |
23 | } from '../../utils' | 23 | } from '../../../../shared/utils' |
24 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 24 | import { |
25 | checkBadCountPagination, | ||
26 | checkBadSortPagination, | ||
27 | checkBadStartPagination | ||
28 | } from '../../../../shared/utils/requests/check-api-params' | ||
25 | import { User } from '../../../../shared/models/users' | 29 | import { User } from '../../../../shared/models/users' |
26 | import { join } from 'path' | 30 | import { join } from 'path' |
27 | 31 | ||
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 5241832fe..5981780ed 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts | |||
@@ -6,9 +6,13 @@ import { | |||
6 | createUser, | 6 | createUser, |
7 | flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | 7 | flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, |
8 | uploadVideo, userLogin | 8 | uploadVideo, userLogin |
9 | } from '../../utils' | 9 | } from '../../../../shared/utils' |
10 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 10 | import { |
11 | import { addVideoCommentThread } from '../../utils/videos/video-comments' | 11 | checkBadCountPagination, |
12 | checkBadSortPagination, | ||
13 | checkBadStartPagination | ||
14 | } from '../../../../shared/utils/requests/check-api-params' | ||
15 | import { addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' | ||
12 | 16 | ||
13 | const expect = chai.expect | 17 | const expect = chai.expect |
14 | 18 | ||
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index b51f3d2cd..7bf187007 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -18,9 +18,13 @@ import { | |||
18 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
19 | updateCustomSubConfig, | 19 | updateCustomSubConfig, |
20 | userLogin | 20 | userLogin |
21 | } from '../../utils' | 21 | } from '../../../../shared/utils' |
22 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 22 | import { |
23 | import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports' | 23 | checkBadCountPagination, |
24 | checkBadSortPagination, | ||
25 | checkBadStartPagination | ||
26 | } from '../../../../shared/utils/requests/check-api-params' | ||
27 | import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/utils/videos/video-imports' | ||
24 | 28 | ||
25 | describe('Test video imports API validator', function () { | 29 | describe('Test video imports API validator', function () { |
26 | const path = '/api/v1/videos/imports' | 30 | const path = '/api/v1/videos/imports' |
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index 784cd8ba1..e998c8a3d 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts | |||
@@ -11,7 +11,7 @@ import { | |||
11 | ServerInfo, | 11 | ServerInfo, |
12 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
13 | userLogin | 13 | userLogin |
14 | } from '../../utils' | 14 | } from '../../../../shared/utils' |
15 | import { UserRole } from '../../../../shared/models/users' | 15 | import { UserRole } from '../../../../shared/models/users' |
16 | 16 | ||
17 | const expect = chai.expect | 17 | const expect = chai.expect |
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 808c3b616..8c079a956 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts | |||
@@ -3,20 +3,25 @@ | |||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { | 5 | import { |
6 | checkBadCountPagination, | ||
7 | checkBadStartPagination, | ||
6 | flushTests, | 8 | flushTests, |
7 | killallServers, | 9 | killallServers, |
10 | makeGetRequest, | ||
8 | makePostBodyRequest, | 11 | makePostBodyRequest, |
9 | makePutBodyRequest, | 12 | makePutBodyRequest, |
10 | runServer, | 13 | runServer, |
11 | ServerInfo, | 14 | ServerInfo, |
12 | setAccessTokensToServers, | 15 | setAccessTokensToServers, |
13 | uploadVideo | 16 | uploadVideo |
14 | } from '../../utils' | 17 | } from '../../../../shared/utils' |
15 | 18 | ||
16 | const expect = chai.expect | 19 | const expect = chai.expect |
17 | 20 | ||
18 | describe('Test videos history API validator', function () { | 21 | describe('Test videos history API validator', function () { |
19 | let path: string | 22 | let watchingPath: string |
23 | let myHistoryPath = '/api/v1/users/me/history/videos' | ||
24 | let myHistoryRemove = myHistoryPath + '/remove' | ||
20 | let server: ServerInfo | 25 | let server: ServerInfo |
21 | 26 | ||
22 | // --------------------------------------------------------------- | 27 | // --------------------------------------------------------------- |
@@ -33,14 +38,14 @@ describe('Test videos history API validator', function () { | |||
33 | const res = await uploadVideo(server.url, server.accessToken, {}) | 38 | const res = await uploadVideo(server.url, server.accessToken, {}) |
34 | const videoUUID = res.body.video.uuid | 39 | const videoUUID = res.body.video.uuid |
35 | 40 | ||
36 | path = '/api/v1/videos/' + videoUUID + '/watching' | 41 | watchingPath = '/api/v1/videos/' + videoUUID + '/watching' |
37 | }) | 42 | }) |
38 | 43 | ||
39 | describe('When notifying a user is watching a video', function () { | 44 | describe('When notifying a user is watching a video', function () { |
40 | 45 | ||
41 | it('Should fail with an unauthenticated user', async function () { | 46 | it('Should fail with an unauthenticated user', async function () { |
42 | const fields = { currentTime: 5 } | 47 | const fields = { currentTime: 5 } |
43 | await makePutBodyRequest({ url: server.url, path, fields, statusCodeExpected: 401 }) | 48 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 }) |
44 | }) | 49 | }) |
45 | 50 | ||
46 | it('Should fail with an incorrect video id', async function () { | 51 | it('Should fail with an incorrect video id', async function () { |
@@ -58,13 +63,68 @@ describe('Test videos history API validator', function () { | |||
58 | 63 | ||
59 | it('Should fail with a bad current time', async function () { | 64 | it('Should fail with a bad current time', async function () { |
60 | const fields = { currentTime: 'hello' } | 65 | const fields = { currentTime: 'hello' } |
61 | await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) | 66 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 }) |
62 | }) | 67 | }) |
63 | 68 | ||
64 | it('Should succeed with the correct parameters', async function () { | 69 | it('Should succeed with the correct parameters', async function () { |
65 | const fields = { currentTime: 5 } | 70 | const fields = { currentTime: 5 } |
66 | 71 | ||
67 | await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 204 }) | 72 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 }) |
73 | }) | ||
74 | }) | ||
75 | |||
76 | describe('When listing user videos history', function () { | ||
77 | it('Should fail with a bad start pagination', async function () { | ||
78 | await checkBadStartPagination(server.url, myHistoryPath, server.accessToken) | ||
79 | }) | ||
80 | |||
81 | it('Should fail with a bad count pagination', async function () { | ||
82 | await checkBadCountPagination(server.url, myHistoryPath, server.accessToken) | ||
83 | }) | ||
84 | |||
85 | it('Should fail with an unauthenticated user', async function () { | ||
86 | await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 }) | ||
87 | }) | ||
88 | |||
89 | it('Should succeed with the correct params', async function () { | ||
90 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 }) | ||
91 | }) | ||
92 | }) | ||
93 | |||
94 | describe('When removing user videos history', function () { | ||
95 | it('Should fail with an unauthenticated user', async function () { | ||
96 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 }) | ||
97 | }) | ||
98 | |||
99 | it('Should fail with a bad beforeDate parameter', async function () { | ||
100 | const body = { beforeDate: '15' } | ||
101 | await makePostBodyRequest({ | ||
102 | url: server.url, | ||
103 | token: server.accessToken, | ||
104 | path: myHistoryRemove, | ||
105 | fields: body, | ||
106 | statusCodeExpected: 400 | ||
107 | }) | ||
108 | }) | ||
109 | |||
110 | it('Should succeed with a valid beforeDate param', async function () { | ||
111 | const body = { beforeDate: new Date().toISOString() } | ||
112 | await makePostBodyRequest({ | ||
113 | url: server.url, | ||
114 | token: server.accessToken, | ||
115 | path: myHistoryRemove, | ||
116 | fields: body, | ||
117 | statusCodeExpected: 204 | ||
118 | }) | ||
119 | }) | ||
120 | |||
121 | it('Should succeed without body', async function () { | ||
122 | await makePostBodyRequest({ | ||
123 | url: server.url, | ||
124 | token: server.accessToken, | ||
125 | path: myHistoryRemove, | ||
126 | statusCodeExpected: 204 | ||
127 | }) | ||
68 | }) | 128 | }) |
69 | }) | 129 | }) |
70 | 130 | ||
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 699f135c7..f26b91435 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts | |||
@@ -8,9 +8,13 @@ import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enu | |||
8 | import { | 8 | import { |
9 | createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, | 9 | createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, |
10 | makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin | 10 | makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin |
11 | } from '../../utils' | 11 | } from '../../../../shared/utils' |
12 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 12 | import { |
13 | import { getAccountsList } from '../../utils/users/accounts' | 13 | checkBadCountPagination, |
14 | checkBadSortPagination, | ||
15 | checkBadStartPagination | ||
16 | } from '../../../../shared/utils/requests/check-api-params' | ||
17 | import { getAccountsList } from '../../../../shared/utils/users/accounts' | ||
14 | 18 | ||
15 | const expect = chai.expect | 19 | const expect = chai.expect |
16 | 20 | ||
@@ -316,10 +320,15 @@ describe('Test videos API validator', function () { | |||
316 | 320 | ||
317 | it('Should fail without an incorrect input file', async function () { | 321 | it('Should fail without an incorrect input file', async function () { |
318 | const fields = baseCorrectParams | 322 | const fields = baseCorrectParams |
319 | const attaches = { | 323 | let attaches = { |
320 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') | 324 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') |
321 | } | 325 | } |
322 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 326 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
327 | |||
328 | attaches = { | ||
329 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv') | ||
330 | } | ||
331 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | ||
323 | }) | 332 | }) |
324 | 333 | ||
325 | it('Should fail with an incorrect thumbnail file', async function () { | 334 | it('Should fail with an incorrect thumbnail file', async function () { |