aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
committerChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
commit0883b3245bf0deb9106c4041e9afbd3521b79280 (patch)
treefcb73005e0b31a3b763ee5d22d5fc39c2da89907 /server/tests/api
parent04ed10b21e8e1339514faae0bb690e4d97c23b0a (diff)
downloadPeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.gz
PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.zst
PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.zip
Add ability to choose what policy we have for NSFW videos
There is a global instance setting and a per user setting
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts19
-rw-r--r--server/tests/api/check-params/users.ts6
-rw-r--r--server/tests/api/server/config.ts5
-rw-r--r--server/tests/api/users/users.ts26
-rw-r--r--server/tests/api/videos/video-nsfw.ts197
5 files changed, 236 insertions, 17 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 3fe517fad..58b780f38 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -6,7 +6,7 @@ import { CustomConfig } from '../../../../shared/models/server/custom-config.mod
6 6
7import { 7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, 8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin 9 setAccessTokensToServers, userLogin, immutableAssign
10} from '../../utils' 10} from '../../utils'
11 11
12describe('Test config API validators', function () { 12describe('Test config API validators', function () {
@@ -20,6 +20,7 @@ describe('Test config API validators', function () {
20 description: 'my super description', 20 description: 'my super description',
21 terms: 'my super terms', 21 terms: 'my super terms',
22 defaultClientRoute: '/videos/recently-added', 22 defaultClientRoute: '/videos/recently-added',
23 defaultNSFWPolicy: 'blur',
23 customizations: { 24 customizations: {
24 javascript: 'alert("coucou")', 25 javascript: 'alert("coucou")',
25 css: 'body { background-color: red; }' 26 css: 'body { background-color: red; }'
@@ -122,6 +123,22 @@ describe('Test config API validators', function () {
122 }) 123 })
123 }) 124 })
124 125
126 it('Should fail with a bad default NSFW policy', async function () {
127 const newUpdateParams = immutableAssign(updateParams, {
128 instance: {
129 defaultNSFWPolicy: 'hello'
130 }
131 })
132
133 await makePutBodyRequest({
134 url: server.url,
135 path,
136 fields: newUpdateParams,
137 token: server.accessToken,
138 statusCodeExpected: 400
139 })
140 })
141
125 it('Should success with the correct parameters', async function () { 142 it('Should success with the correct parameters', async function () {
126 await makePutBodyRequest({ 143 await makePutBodyRequest({
127 url: server.url, 144 url: server.url,
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index a3e415b94..e8a6ffd19 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -231,9 +231,9 @@ describe('Test users API validators', function () {
231 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 231 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
232 }) 232 })
233 233
234 it('Should fail with an invalid display NSFW attribute', async function () { 234 it('Should fail with an invalid NSFW policy attribute', async function () {
235 const fields = { 235 const fields = {
236 displayNSFW: -1 236 nsfwPolicy: 'hello'
237 } 237 }
238 238
239 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 239 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
@@ -266,7 +266,7 @@ describe('Test users API validators', function () {
266 it('Should succeed with the correct params', async function () { 266 it('Should succeed with the correct params', async function () {
267 const fields = { 267 const fields = {
268 password: 'my super password', 268 password: 'my super password',
269 displayNSFW: true, 269 nsfwPolicy: 'blur',
270 autoPlayVideo: false, 270 autoPlayVideo: false,
271 email: 'super_email@example.com' 271 email: 'super_email@example.com'
272 } 272 }
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index e17588142..3f1b1532c 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -59,6 +59,7 @@ describe('Test config', function () {
59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
60 expect(data.instance.terms).to.equal('No terms for now.') 60 expect(data.instance.terms).to.equal('No terms for now.')
61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
62 expect(data.instance.defaultNSFWPolicy).to.equal('display')
62 expect(data.instance.customizations.css).to.be.empty 63 expect(data.instance.customizations.css).to.be.empty
63 expect(data.instance.customizations.javascript).to.be.empty 64 expect(data.instance.customizations.javascript).to.be.empty
64 expect(data.cache.previews.size).to.equal(1) 65 expect(data.cache.previews.size).to.equal(1)
@@ -83,6 +84,7 @@ describe('Test config', function () {
83 description: 'my super description', 84 description: 'my super description',
84 terms: 'my super terms', 85 terms: 'my super terms',
85 defaultClientRoute: '/videos/recently-added', 86 defaultClientRoute: '/videos/recently-added',
87 defaultNSFWPolicy: 'blur' as 'blur',
86 customizations: { 88 customizations: {
87 javascript: 'alert("coucou")', 89 javascript: 'alert("coucou")',
88 css: 'body { background-color: red; }' 90 css: 'body { background-color: red; }'
@@ -125,6 +127,7 @@ describe('Test config', function () {
125 expect(data.instance.description).to.equal('my super description') 127 expect(data.instance.description).to.equal('my super description')
126 expect(data.instance.terms).to.equal('my super terms') 128 expect(data.instance.terms).to.equal('my super terms')
127 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 129 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
130 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
128 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 131 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
129 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 132 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
130 expect(data.cache.previews.size).to.equal(2) 133 expect(data.cache.previews.size).to.equal(2)
@@ -156,6 +159,7 @@ describe('Test config', function () {
156 expect(data.instance.description).to.equal('my super description') 159 expect(data.instance.description).to.equal('my super description')
157 expect(data.instance.terms).to.equal('my super terms') 160 expect(data.instance.terms).to.equal('my super terms')
158 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 161 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
162 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
159 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 163 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
160 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 164 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
161 expect(data.cache.previews.size).to.equal(2) 165 expect(data.cache.previews.size).to.equal(2)
@@ -198,6 +202,7 @@ describe('Test config', function () {
198 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 202 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
199 expect(data.instance.terms).to.equal('No terms for now.') 203 expect(data.instance.terms).to.equal('No terms for now.')
200 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 204 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
205 expect(data.instance.defaultNSFWPolicy).to.equal('display')
201 expect(data.instance.customizations.css).to.be.empty 206 expect(data.instance.customizations.css).to.be.empty
202 expect(data.instance.customizations.javascript).to.be.empty 207 expect(data.instance.customizations.javascript).to.be.empty
203 expect(data.cache.previews.size).to.equal(1) 208 expect(data.cache.previews.size).to.equal(1)
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index b6ab4f660..1192ef9e4 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -168,7 +168,7 @@ describe('Test users', function () {
168 168
169 expect(user.username).to.equal('user_1') 169 expect(user.username).to.equal('user_1')
170 expect(user.email).to.equal('user_1@example.com') 170 expect(user.email).to.equal('user_1@example.com')
171 expect(user.displayNSFW).to.be.false 171 expect(user.nsfwPolicy).to.equal('display')
172 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 172 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
173 expect(user.roleLabel).to.equal('User') 173 expect(user.roleLabel).to.equal('User')
174 expect(user.id).to.be.a('number') 174 expect(user.id).to.be.a('number')
@@ -215,12 +215,12 @@ describe('Test users', function () {
215 const user = users[ 0 ] 215 const user = users[ 0 ]
216 expect(user.username).to.equal('user_1') 216 expect(user.username).to.equal('user_1')
217 expect(user.email).to.equal('user_1@example.com') 217 expect(user.email).to.equal('user_1@example.com')
218 expect(user.displayNSFW).to.be.false 218 expect(user.nsfwPolicy).to.equal('display')
219 219
220 const rootUser = users[ 1 ] 220 const rootUser = users[ 1 ]
221 expect(rootUser.username).to.equal('root') 221 expect(rootUser.username).to.equal('root')
222 expect(rootUser.email).to.equal('admin1@example.com') 222 expect(rootUser.email).to.equal('admin1@example.com')
223 expect(rootUser.displayNSFW).to.be.false 223 expect(user.nsfwPolicy).to.equal('display')
224 224
225 userId = user.id 225 userId = user.id
226 }) 226 })
@@ -239,7 +239,7 @@ describe('Test users', function () {
239 expect(user.username).to.equal('root') 239 expect(user.username).to.equal('root')
240 expect(user.email).to.equal('admin1@example.com') 240 expect(user.email).to.equal('admin1@example.com')
241 expect(user.roleLabel).to.equal('Administrator') 241 expect(user.roleLabel).to.equal('Administrator')
242 expect(user.displayNSFW).to.be.false 242 expect(user.nsfwPolicy).to.equal('display')
243 }) 243 })
244 244
245 it('Should list only the first user by username desc', async function () { 245 it('Should list only the first user by username desc', async function () {
@@ -254,7 +254,7 @@ describe('Test users', function () {
254 const user = users[ 0 ] 254 const user = users[ 0 ]
255 expect(user.username).to.equal('user_1') 255 expect(user.username).to.equal('user_1')
256 expect(user.email).to.equal('user_1@example.com') 256 expect(user.email).to.equal('user_1@example.com')
257 expect(user.displayNSFW).to.be.false 257 expect(user.nsfwPolicy).to.equal('display')
258 }) 258 })
259 259
260 it('Should list only the second user by createdAt desc', async function () { 260 it('Should list only the second user by createdAt desc', async function () {
@@ -269,7 +269,7 @@ describe('Test users', function () {
269 const user = users[ 0 ] 269 const user = users[ 0 ]
270 expect(user.username).to.equal('user_1') 270 expect(user.username).to.equal('user_1')
271 expect(user.email).to.equal('user_1@example.com') 271 expect(user.email).to.equal('user_1@example.com')
272 expect(user.displayNSFW).to.be.false 272 expect(user.nsfwPolicy).to.equal('display')
273 }) 273 })
274 274
275 it('Should list all the users by createdAt asc', async function () { 275 it('Should list all the users by createdAt asc', async function () {
@@ -283,11 +283,11 @@ describe('Test users', function () {
283 283
284 expect(users[ 0 ].username).to.equal('root') 284 expect(users[ 0 ].username).to.equal('root')
285 expect(users[ 0 ].email).to.equal('admin1@example.com') 285 expect(users[ 0 ].email).to.equal('admin1@example.com')
286 expect(users[ 0 ].displayNSFW).to.be.false 286 expect(users[ 0 ].nsfwPolicy).to.equal('display')
287 287
288 expect(users[ 1 ].username).to.equal('user_1') 288 expect(users[ 1 ].username).to.equal('user_1')
289 expect(users[ 1 ].email).to.equal('user_1@example.com') 289 expect(users[ 1 ].email).to.equal('user_1@example.com')
290 expect(users[ 1 ].displayNSFW).to.be.false 290 expect(users[ 1 ].nsfwPolicy).to.equal('display')
291 }) 291 })
292 292
293 it('Should update my password', async function () { 293 it('Should update my password', async function () {
@@ -305,7 +305,7 @@ describe('Test users', function () {
305 await updateMyUser({ 305 await updateMyUser({
306 url: server.url, 306 url: server.url,
307 accessToken: accessTokenUser, 307 accessToken: accessTokenUser,
308 displayNSFW: true 308 nsfwPolicy: 'do_not_list'
309 }) 309 })
310 310
311 const res = await getMyUserInformation(server.url, accessTokenUser) 311 const res = await getMyUserInformation(server.url, accessTokenUser)
@@ -313,7 +313,7 @@ describe('Test users', function () {
313 313
314 expect(user.username).to.equal('user_1') 314 expect(user.username).to.equal('user_1')
315 expect(user.email).to.equal('user_1@example.com') 315 expect(user.email).to.equal('user_1@example.com')
316 expect(user.displayNSFW).to.be.ok 316 expect(user.nsfwPolicy).to.equal('do_not_list')
317 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 317 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
318 expect(user.id).to.be.a('number') 318 expect(user.id).to.be.a('number')
319 expect(user.account.description).to.be.null 319 expect(user.account.description).to.be.null
@@ -344,7 +344,7 @@ describe('Test users', function () {
344 344
345 expect(user.username).to.equal('user_1') 345 expect(user.username).to.equal('user_1')
346 expect(user.email).to.equal('updated@example.com') 346 expect(user.email).to.equal('updated@example.com')
347 expect(user.displayNSFW).to.be.ok 347 expect(user.nsfwPolicy).to.equal('do_not_list')
348 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 348 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
349 expect(user.id).to.be.a('number') 349 expect(user.id).to.be.a('number')
350 expect(user.account.description).to.be.null 350 expect(user.account.description).to.be.null
@@ -377,7 +377,7 @@ describe('Test users', function () {
377 377
378 expect(user.username).to.equal('user_1') 378 expect(user.username).to.equal('user_1')
379 expect(user.email).to.equal('updated@example.com') 379 expect(user.email).to.equal('updated@example.com')
380 expect(user.displayNSFW).to.be.ok 380 expect(user.nsfwPolicy).to.equal('do_not_list')
381 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 381 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
382 expect(user.id).to.be.a('number') 382 expect(user.id).to.be.a('number')
383 expect(user.account.description).to.equal('my super description updated') 383 expect(user.account.description).to.equal('my super description updated')
@@ -398,7 +398,7 @@ describe('Test users', function () {
398 398
399 expect(user.username).to.equal('user_1') 399 expect(user.username).to.equal('user_1')
400 expect(user.email).to.equal('updated2@example.com') 400 expect(user.email).to.equal('updated2@example.com')
401 expect(user.displayNSFW).to.be.ok 401 expect(user.nsfwPolicy).to.equal('do_not_list')
402 expect(user.videoQuota).to.equal(42) 402 expect(user.videoQuota).to.equal(42)
403 expect(user.roleLabel).to.equal('Moderator') 403 expect(user.roleLabel).to.equal('Moderator')
404 expect(user.id).to.be.a('number') 404 expect(user.id).to.be.a('number')
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
new file mode 100644
index 000000000..4e5ab11ce
--- /dev/null
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -0,0 +1,197 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
6import { userLogin } from '../../utils/users/login'
7import { createUser } from '../../utils/users/users'
8import { getMyVideos } from '../../utils/videos/videos'
9import {
10 getConfig, getCustomConfig,
11 getMyUserInformation,
12 getVideosListWithToken,
13 runServer,
14 searchVideo,
15 searchVideoWithToken, updateCustomConfig,
16 updateMyUser
17} from '../../utils'
18import { ServerConfig } from '../../../../shared/models'
19import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
20
21const expect = chai.expect
22
23describe('Test video NSFW policy', function () {
24 let server: ServerInfo
25 let userAccessToken: string
26 let customConfig: CustomConfig
27
28 before(async function () {
29 this.timeout(50000)
30
31 await flushTests()
32 server = await runServer(1)
33
34 // Get the access tokens
35 await setAccessTokensToServers([ server ])
36
37 {
38 const attributes = { name: 'nsfw', nsfw: true }
39 await uploadVideo(server.url, server.accessToken, attributes)
40 }
41
42 {
43 const attributes = { name: 'normal', nsfw: false }
44 await uploadVideo(server.url, server.accessToken, attributes)
45 }
46
47 {
48 const res = await getCustomConfig(server.url, server.accessToken)
49 customConfig = res.body
50 }
51 })
52
53 describe('Instance default NSFW policy', function () {
54 it('Should display NSFW videos with display default NSFW policy', async function () {
55 const resConfig = await getConfig(server.url)
56 const serverConfig: ServerConfig = resConfig.body
57 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
58
59 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
60 expect(res.body.total).to.equal(2)
61
62 const videos = res.body.data
63 expect(videos).to.have.lengthOf(2)
64 expect(videos[ 0 ].name).to.equal('normal')
65 expect(videos[ 1 ].name).to.equal('nsfw')
66 }
67 })
68
69 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
70 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
71 await updateCustomConfig(server.url, server.accessToken, customConfig)
72
73 const resConfig = await getConfig(server.url)
74 const serverConfig: ServerConfig = resConfig.body
75 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
76
77 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
78 expect(res.body.total).to.equal(1)
79
80 const videos = res.body.data
81 expect(videos).to.have.lengthOf(1)
82 expect(videos[ 0 ].name).to.equal('normal')
83 }
84 })
85
86 it('Should display NSFW videos with blur default NSFW policy', async function () {
87 customConfig.instance.defaultNSFWPolicy = 'blur'
88 await updateCustomConfig(server.url, server.accessToken, customConfig)
89
90 const resConfig = await getConfig(server.url)
91 const serverConfig: ServerConfig = resConfig.body
92 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
93
94 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
95 expect(res.body.total).to.equal(2)
96
97 const videos = res.body.data
98 expect(videos).to.have.lengthOf(2)
99 expect(videos[ 0 ].name).to.equal('normal')
100 expect(videos[ 1 ].name).to.equal('nsfw')
101 }
102 })
103 })
104
105 describe('User NSFW policy', function () {
106
107 it('Should create a user having the default nsfw policy', async function () {
108 const username = 'user1'
109 const password = 'my super password'
110 await createUser(server.url, server.accessToken, username, password)
111
112 userAccessToken = await userLogin(server, { username, password })
113
114 const res = await getMyUserInformation(server.url, userAccessToken)
115 const user = res.body
116
117 expect(user.nsfwPolicy).to.equal('blur')
118 })
119
120 it('Should display NSFW videos with blur user NSFW policy', async function () {
121 const results = [
122 await getVideosListWithToken(server.url, userAccessToken),
123 await searchVideoWithToken(server.url, 'n', userAccessToken)
124 ]
125
126 for (const res of results) {
127 expect(res.body.total).to.equal(2)
128
129 const videos = res.body.data
130 expect(videos).to.have.lengthOf(2)
131 expect(videos[ 0 ].name).to.equal('normal')
132 expect(videos[ 1 ].name).to.equal('nsfw')
133 }
134 })
135
136 it('Should display NSFW videos with display user NSFW policy', async function () {
137 await updateMyUser({
138 url: server.url,
139 accessToken: server.accessToken,
140 nsfwPolicy: 'display'
141 })
142
143 const results = [
144 await getVideosListWithToken(server.url, server.accessToken),
145 await searchVideoWithToken(server.url, 'n', server.accessToken)
146 ]
147
148 for (const res of results) {
149 expect(res.body.total).to.equal(2)
150
151 const videos = res.body.data
152 expect(videos).to.have.lengthOf(2)
153 expect(videos[ 0 ].name).to.equal('normal')
154 expect(videos[ 1 ].name).to.equal('nsfw')
155 }
156 })
157
158 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
159 await updateMyUser({
160 url: server.url,
161 accessToken: server.accessToken,
162 nsfwPolicy: 'do_not_list'
163 })
164
165 const results = [
166 await getVideosListWithToken(server.url, server.accessToken),
167 await searchVideoWithToken(server.url, 'n', server.accessToken)
168 ]
169 for (const res of results) {
170 expect(res.body.total).to.equal(1)
171
172 const videos = res.body.data
173 expect(videos).to.have.lengthOf(1)
174 expect(videos[ 0 ].name).to.equal('normal')
175 }
176 })
177
178 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
179 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
180 expect(res.body.total).to.equal(2)
181
182 const videos = res.body.data
183 expect(videos).to.have.lengthOf(2)
184 expect(videos[ 0 ].name).to.equal('normal')
185 expect(videos[ 1 ].name).to.equal('nsfw')
186 })
187 })
188
189 after(async function () {
190 killallServers([ server ])
191
192 // Keep the logs if the test failed
193 if (this['ok']) {
194 await flushTests()
195 }
196 })
197})