diff options
author | Green-Star <Green-Star@users.noreply.github.com> | 2017-09-22 09:13:43 +0200 |
---|---|---|
committer | Bigard Florian <florian.bigard@gmail.com> | 2017-09-22 09:13:43 +0200 |
commit | 792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch) | |
tree | f7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/tests/api/check-params | |
parent | c9d6d155c397d0da0cb2d50064264fc1716f0501 (diff) | |
download | PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.gz PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.zst PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.zip |
Handle blacklist (#84)
* Client: Add list blacklist feature
* Server: Add list blacklist feature
* Client: Add videoId column
* Server: Add some video infos in the REST api
* Client: Add video information in the blacklist list
* Fix sortable columns :)
* Client: Add removeFromBlacklist feature
* Server: Add removeFromBlacklist feature
* Move to TypeScript
* Move to TypeScript and Promises
* Server: Fix blacklist list sort
* Server: Fetch videos informations
* Use common shared interface for client and server
* Add check-params remove blacklisted video tests
* Add check-params list blacklisted videos tests
* Add list blacklist tests
* Add remove from blacklist tests
* Add video blacklist management tests
* Fix rebase onto develop issues
* Server: Add sort on blacklist id column
* Server: Add blacklists library
* Add blacklist id sort test
* Add check-params tests for blacklist list pagination, count and sort
* Fix coding style
* Increase Remote API tests timeout
* Increase Request scheduler API tests timeout
* Fix typo
* Increase video transcoding API tests timeout
* Move tests to Typescript
* Use lodash orderBy method
* Fix typos
* Client: Remove optional tests in blacklist model attributes
* Move blacklist routes from 'blacklists' to 'blacklist'
* CLient: Remove blacklist-list.component.scss
* Rename 'blacklists' files to 'blacklist'
* Use only BlacklistedVideo interface
* Server: Use getFormattedObjects method in listBlacklist method
* Client: Use new coding style
* Server: Use new sort validator methods
* Server: Use new checkParams methods
* Client: Fix sortable columns
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/request-schedulers.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklist.ts | 195 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.ts | 90 |
5 files changed, 198 insertions, 93 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 97f2a19d7..399a05bc3 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -5,4 +5,4 @@ import './users' | |||
5 | import './request-schedulers' | 5 | import './request-schedulers' |
6 | import './videos' | 6 | import './videos' |
7 | import './video-abuses' | 7 | import './video-abuses' |
8 | import './video-blacklists' | 8 | import './video-blacklist' |
diff --git a/server/tests/api/check-params/remotes.ts b/server/tests/api/check-params/remotes.ts index b36f1c08b..9456ae665 100644 --- a/server/tests/api/check-params/remotes.ts +++ b/server/tests/api/check-params/remotes.ts | |||
@@ -14,7 +14,7 @@ describe('Test remote videos API validators', function () { | |||
14 | // --------------------------------------------------------------- | 14 | // --------------------------------------------------------------- |
15 | 15 | ||
16 | before(async function () { | 16 | before(async function () { |
17 | this.timeout(20000) | 17 | this.timeout(60000) |
18 | 18 | ||
19 | await flushTests() | 19 | await flushTests() |
20 | 20 | ||
diff --git a/server/tests/api/check-params/request-schedulers.ts b/server/tests/api/check-params/request-schedulers.ts index c39f5947b..01a54ffa1 100644 --- a/server/tests/api/check-params/request-schedulers.ts +++ b/server/tests/api/check-params/request-schedulers.ts | |||
@@ -20,7 +20,7 @@ describe('Test request schedulers stats API validators', function () { | |||
20 | // --------------------------------------------------------------- | 20 | // --------------------------------------------------------------- |
21 | 21 | ||
22 | before(async function () { | 22 | before(async function () { |
23 | this.timeout(20000) | 23 | this.timeout(60000) |
24 | 24 | ||
25 | await flushTests() | 25 | await flushTests() |
26 | 26 | ||
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts new file mode 100644 index 000000000..80e6f8011 --- /dev/null +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -0,0 +1,195 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as request from 'supertest' | ||
5 | |||
6 | import { | ||
7 | ServerInfo, | ||
8 | flushTests, | ||
9 | runServer, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | createUser, | ||
13 | setAccessTokensToServers, | ||
14 | killallServers, | ||
15 | makePostBodyRequest, | ||
16 | getUserAccessToken | ||
17 | } from '../../utils' | ||
18 | |||
19 | describe('Test video blacklist API validators', function () { | ||
20 | let server: ServerInfo | ||
21 | let userAccessToken = '' | ||
22 | |||
23 | // --------------------------------------------------------------- | ||
24 | |||
25 | before(async function () { | ||
26 | this.timeout(120000) | ||
27 | |||
28 | await flushTests() | ||
29 | |||
30 | server = await runServer(1) | ||
31 | |||
32 | await setAccessTokensToServers([ server ]) | ||
33 | |||
34 | const username = 'user1' | ||
35 | const password = 'my super password' | ||
36 | await createUser(server.url, server.accessToken, username, password) | ||
37 | userAccessToken = await getUserAccessToken(server, { username, password }) | ||
38 | |||
39 | // Upload a video | ||
40 | const videoAttributes = {} | ||
41 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
42 | |||
43 | const res = await getVideosList(server.url) | ||
44 | |||
45 | const videos = res.body.data | ||
46 | server.video = videos[0] | ||
47 | }) | ||
48 | |||
49 | describe('When adding a video in blacklist', function () { | ||
50 | const basePath = '/api/v1/videos/' | ||
51 | |||
52 | it('Should fail with nothing', async function () { | ||
53 | const path = basePath + server.video + '/blacklist' | ||
54 | const fields = {} | ||
55 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
56 | }) | ||
57 | |||
58 | it('Should fail with a wrong video', async function () { | ||
59 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
60 | const fields = {} | ||
61 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | ||
62 | }) | ||
63 | |||
64 | it('Should fail with a non authenticated user', async function () { | ||
65 | const fields = {} | ||
66 | const path = basePath + server.video + '/blacklist' | ||
67 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with a non admin user', async function () { | ||
71 | const fields = {} | ||
72 | const path = basePath + server.video + '/blacklist' | ||
73 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
74 | }) | ||
75 | |||
76 | it('Should fail with a local video', async function () { | ||
77 | const fields = {} | ||
78 | const path = basePath + server.video.id + '/blacklist' | ||
79 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | ||
80 | }) | ||
81 | }) | ||
82 | |||
83 | describe('When removing a video in blacklist', function () { | ||
84 | const basePath = '/api/v1/blacklist/' | ||
85 | |||
86 | it('Should fail with a non authenticated user', async function () { | ||
87 | const path = basePath + server.video.id | ||
88 | |||
89 | await request(server.url) | ||
90 | .delete(path) | ||
91 | .set('Authorization', 'Bearer ' + 'fake token') | ||
92 | .set('Accept', 'application/json') | ||
93 | .expect(401) | ||
94 | }) | ||
95 | |||
96 | it('Should fail with a non admin user', async function () { | ||
97 | const path = basePath + server.video.id | ||
98 | |||
99 | await request(server.url) | ||
100 | .delete(path) | ||
101 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
102 | .set('Accept', 'application/json') | ||
103 | .expect(403) | ||
104 | }) | ||
105 | |||
106 | it('Should fail with an incorrect id', async function () { | ||
107 | const path = basePath + 'foobar' | ||
108 | |||
109 | await request(server.url) | ||
110 | .delete(path) | ||
111 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
112 | .set('Accept', 'application/json') | ||
113 | .expect(400) | ||
114 | }) | ||
115 | |||
116 | it('Should fail with a not blacklisted video', async function () { | ||
117 | // The video was not added to the blacklist so it should fail | ||
118 | const path = basePath + server.video.id | ||
119 | |||
120 | await request(server.url) | ||
121 | .delete(path) | ||
122 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
123 | .set('Accept', 'application/json') | ||
124 | .expect(404) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('When listing videos in blacklist', function () { | ||
129 | const basePath = '/api/v1/blacklist/' | ||
130 | |||
131 | it('Should fail with a non authenticated user', async function () { | ||
132 | const path = basePath | ||
133 | |||
134 | await request(server.url) | ||
135 | .get(path) | ||
136 | .query({ sort: 'createdAt' }) | ||
137 | .set('Accept', 'application/json') | ||
138 | .set('Authorization', 'Bearer ' + 'fake token') | ||
139 | .expect(401) | ||
140 | }) | ||
141 | |||
142 | it('Should fail with a non admin user', async function () { | ||
143 | const path = basePath | ||
144 | |||
145 | await request(server.url) | ||
146 | .get(path) | ||
147 | .query({ sort: 'createdAt' }) | ||
148 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
149 | .set('Accept', 'application/json') | ||
150 | .expect(403) | ||
151 | }) | ||
152 | |||
153 | it('Should fail with a bad start pagination', async function () { | ||
154 | const path = basePath | ||
155 | |||
156 | await request(server.url) | ||
157 | .get(path) | ||
158 | .query({ start: 'foobar' }) | ||
159 | .set('Accept', 'application/json') | ||
160 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
161 | .expect(400) | ||
162 | }) | ||
163 | |||
164 | it('Should fail with a bad count pagination', async function () { | ||
165 | const path = basePath | ||
166 | |||
167 | await request(server.url) | ||
168 | .get(path) | ||
169 | .query({ count: 'foobar' }) | ||
170 | .set('Accept', 'application/json') | ||
171 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
172 | .expect(400) | ||
173 | }) | ||
174 | |||
175 | it('Should fail with an incorrect sort', async function () { | ||
176 | const path = basePath | ||
177 | |||
178 | await request(server.url) | ||
179 | .get(path) | ||
180 | .query({ sort: 'foobar' }) | ||
181 | .set('Accept', 'application/json') | ||
182 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
183 | .expect(400) | ||
184 | }) | ||
185 | }) | ||
186 | |||
187 | after(async function () { | ||
188 | killallServers([ server ]) | ||
189 | |||
190 | // Keep the logs if the test failed | ||
191 | if (this['ok']) { | ||
192 | await flushTests() | ||
193 | } | ||
194 | }) | ||
195 | }) | ||
diff --git a/server/tests/api/check-params/video-blacklists.ts b/server/tests/api/check-params/video-blacklists.ts deleted file mode 100644 index d0ad78ff1..000000000 --- a/server/tests/api/check-params/video-blacklists.ts +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | ServerInfo, | ||
7 | flushTests, | ||
8 | runServer, | ||
9 | uploadVideo, | ||
10 | getVideosList, | ||
11 | createUser, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | makePostBodyRequest, | ||
15 | getUserAccessToken | ||
16 | } from '../../utils' | ||
17 | |||
18 | describe('Test video blacklists API validators', function () { | ||
19 | let server: ServerInfo | ||
20 | let userAccessToken = '' | ||
21 | |||
22 | // --------------------------------------------------------------- | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | await flushTests() | ||
28 | |||
29 | server = await runServer(1) | ||
30 | |||
31 | await setAccessTokensToServers([ server ]) | ||
32 | |||
33 | const username = 'user1' | ||
34 | const password = 'my super password' | ||
35 | await createUser(server.url, server.accessToken, username, password) | ||
36 | userAccessToken = await getUserAccessToken(server, { username, password }) | ||
37 | |||
38 | // Upload a video | ||
39 | const videoAttributes = {} | ||
40 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
41 | |||
42 | const res = await getVideosList(server.url) | ||
43 | |||
44 | const videos = res.body.data | ||
45 | server.video = videos[0] | ||
46 | }) | ||
47 | |||
48 | describe('When adding a video in blacklist', function () { | ||
49 | const basePath = '/api/v1/videos/' | ||
50 | |||
51 | it('Should fail with nothing', async function () { | ||
52 | const path = basePath + server.video + '/blacklist' | ||
53 | const fields = {} | ||
54 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with a wrong video', async function () { | ||
58 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
59 | const fields = {} | ||
60 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | ||
61 | }) | ||
62 | |||
63 | it('Should fail with a non authenticated user', async function () { | ||
64 | const fields = {} | ||
65 | const path = basePath + server.video + '/blacklist' | ||
66 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non admin user', async function () { | ||
70 | const fields = {} | ||
71 | const path = basePath + server.video + '/blacklist' | ||
72 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
73 | }) | ||
74 | |||
75 | it('Should fail with a local video', async function () { | ||
76 | const fields = {} | ||
77 | const path = basePath + server.video.id + '/blacklist' | ||
78 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | ||
79 | }) | ||
80 | }) | ||
81 | |||
82 | after(async function () { | ||
83 | killallServers([ server ]) | ||
84 | |||
85 | // Keep the logs if the test failed | ||
86 | if (this['ok']) { | ||
87 | await flushTests() | ||
88 | } | ||
89 | }) | ||
90 | }) | ||