users.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /* tslint:disable:no-unused-expression */
  2. import { omit } from 'lodash'
  3. import 'mocha'
  4. import { join } from 'path'
  5. import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
  6. import {
  7. createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
  8. makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, flushAndRunServer, ServerInfo, setAccessTokensToServers,
  9. updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser
  10. } from '../../../../shared/extra-utils'
  11. import {
  12. checkBadCountPagination,
  13. checkBadSortPagination,
  14. checkBadStartPagination
  15. } from '../../../../shared/extra-utils/requests/check-api-params'
  16. import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
  17. import { VideoPrivacy } from '../../../../shared/models/videos'
  18. import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
  19. import { expect } from 'chai'
  20. import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
  21. describe('Test users API validators', function () {
  22. const path = '/api/v1/users/'
  23. let userId: number
  24. let rootId: number
  25. let videoId: number
  26. let server: ServerInfo
  27. let serverWithRegistrationDisabled: ServerInfo
  28. let userAccessToken = ''
  29. let channelId: number
  30. const user = {
  31. username: 'user1',
  32. password: 'my super password'
  33. }
  34. // ---------------------------------------------------------------
  35. before(async function () {
  36. this.timeout(30000)
  37. server = await flushAndRunServer(1)
  38. serverWithRegistrationDisabled = await flushAndRunServer(2)
  39. await setAccessTokensToServers([ server ])
  40. const videoQuota = 42000000
  41. await createUser({
  42. url: server.url,
  43. accessToken: server.accessToken,
  44. username: user.username,
  45. password: user.password,
  46. videoQuota: videoQuota
  47. })
  48. userAccessToken = await userLogin(server, user)
  49. {
  50. const res = await getMyUserInformation(server.url, server.accessToken)
  51. channelId = res.body.videoChannels[ 0 ].id
  52. }
  53. {
  54. const res = await uploadVideo(server.url, server.accessToken, {})
  55. videoId = res.body.video.id
  56. }
  57. })
  58. describe('When listing users', function () {
  59. it('Should fail with a bad start pagination', async function () {
  60. await checkBadStartPagination(server.url, path, server.accessToken)
  61. })
  62. it('Should fail with a bad count pagination', async function () {
  63. await checkBadCountPagination(server.url, path, server.accessToken)
  64. })
  65. it('Should fail with an incorrect sort', async function () {
  66. await checkBadSortPagination(server.url, path, server.accessToken)
  67. })
  68. it('Should fail with a non authenticated user', async function () {
  69. await makeGetRequest({
  70. url: server.url,
  71. path,
  72. statusCodeExpected: 401
  73. })
  74. })
  75. it('Should fail with a non admin user', async function () {
  76. await makeGetRequest({
  77. url: server.url,
  78. path,
  79. token: userAccessToken,
  80. statusCodeExpected: 403
  81. })
  82. })
  83. })
  84. describe('When adding a new user', function () {
  85. const baseCorrectParams = {
  86. username: 'user2',
  87. email: 'test@example.com',
  88. password: 'my super password',
  89. videoQuota: -1,
  90. videoQuotaDaily: -1,
  91. role: UserRole.USER,
  92. adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
  93. }
  94. it('Should fail with a too small username', async function () {
  95. const fields = immutableAssign(baseCorrectParams, { username: '' })
  96. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  97. })
  98. it('Should fail with a too long username', async function () {
  99. const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
  100. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  101. })
  102. it('Should fail with a not lowercase username', async function () {
  103. const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
  104. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  105. })
  106. it('Should fail with an incorrect username', async function () {
  107. const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
  108. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  109. })
  110. it('Should fail with a missing email', async function () {
  111. const fields = omit(baseCorrectParams, 'email')
  112. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  113. })
  114. it('Should fail with an invalid email', async function () {
  115. const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
  116. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  117. })
  118. it('Should fail with a too small password', async function () {
  119. const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
  120. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  121. })
  122. it('Should fail with a too long password', async function () {
  123. const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
  124. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  125. })
  126. it('Should fail with invalid admin flags', async function () {
  127. const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
  128. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  129. })
  130. it('Should fail with an non authenticated user', async function () {
  131. await makePostBodyRequest({
  132. url: server.url,
  133. path,
  134. token: 'super token',
  135. fields: baseCorrectParams,
  136. statusCodeExpected: 401
  137. })
  138. })
  139. it('Should fail if we add a user with the same username', async function () {
  140. const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
  141. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
  142. })
  143. it('Should fail if we add a user with the same email', async function () {
  144. const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
  145. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
  146. })
  147. it('Should fail without a videoQuota', async function () {
  148. const fields = omit(baseCorrectParams, 'videoQuota')
  149. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  150. })
  151. it('Should fail without a videoQuotaDaily', async function () {
  152. const fields = omit(baseCorrectParams, 'videoQuotaDaily')
  153. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  154. })
  155. it('Should fail with an invalid videoQuota', async function () {
  156. const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
  157. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  158. })
  159. it('Should fail with an invalid videoQuotaDaily', async function () {
  160. const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
  161. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  162. })
  163. it('Should fail without a user role', async function () {
  164. const fields = omit(baseCorrectParams, 'role')
  165. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  166. })
  167. it('Should fail with an invalid user role', async function () {
  168. const fields = immutableAssign(baseCorrectParams, { role: 88989 })
  169. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  170. })
  171. it('Should fail with a "peertube" username', async function () {
  172. const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
  173. await makePostBodyRequest({
  174. url: server.url,
  175. path,
  176. token: server.accessToken,
  177. fields,
  178. statusCodeExpected: 409
  179. })
  180. })
  181. it('Should succeed with the correct params', async function () {
  182. await makePostBodyRequest({
  183. url: server.url,
  184. path,
  185. token: server.accessToken,
  186. fields: baseCorrectParams,
  187. statusCodeExpected: 200
  188. })
  189. })
  190. it('Should fail with a non admin user', async function () {
  191. const user = {
  192. username: 'user1',
  193. password: 'my super password'
  194. }
  195. userAccessToken = await userLogin(server, user)
  196. const fields = {
  197. username: 'user3',
  198. email: 'test@example.com',
  199. password: 'my super password',
  200. videoQuota: 42000000
  201. }
  202. await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
  203. })
  204. })
  205. describe('When updating my account', function () {
  206. it('Should fail with an invalid email attribute', async function () {
  207. const fields = {
  208. email: 'blabla'
  209. }
  210. await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
  211. })
  212. it('Should fail with a too small password', async function () {
  213. const fields = {
  214. currentPassword: 'my super password',
  215. password: 'bla'
  216. }
  217. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  218. })
  219. it('Should fail with a too long password', async function () {
  220. const fields = {
  221. currentPassword: 'my super password',
  222. password: 'super'.repeat(61)
  223. }
  224. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  225. })
  226. it('Should fail without the current password', async function () {
  227. const fields = {
  228. currentPassword: 'my super password',
  229. password: 'super'.repeat(61)
  230. }
  231. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  232. })
  233. it('Should fail with an invalid current password', async function () {
  234. const fields = {
  235. currentPassword: 'my super password fail',
  236. password: 'super'.repeat(61)
  237. }
  238. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
  239. })
  240. it('Should fail with an invalid NSFW policy attribute', async function () {
  241. const fields = {
  242. nsfwPolicy: 'hello'
  243. }
  244. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  245. })
  246. it('Should fail with an invalid autoPlayVideo attribute', async function () {
  247. const fields = {
  248. autoPlayVideo: -1
  249. }
  250. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  251. })
  252. it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
  253. const fields = {
  254. videosHistoryEnabled: -1
  255. }
  256. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  257. })
  258. it('Should fail with an non authenticated user', async function () {
  259. const fields = {
  260. currentPassword: 'my super password',
  261. password: 'my super password'
  262. }
  263. await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
  264. })
  265. it('Should fail with a too long description', async function () {
  266. const fields = {
  267. description: 'super'.repeat(201)
  268. }
  269. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
  270. })
  271. it('Should succeed to change password with the correct params', async function () {
  272. const fields = {
  273. currentPassword: 'my super password',
  274. password: 'my super password',
  275. nsfwPolicy: 'blur',
  276. autoPlayVideo: false,
  277. email: 'super_email@example.com'
  278. }
  279. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
  280. })
  281. it('Should succeed without password change with the correct params', async function () {
  282. const fields = {
  283. nsfwPolicy: 'blur',
  284. autoPlayVideo: false,
  285. email: 'super_email@example.com'
  286. }
  287. await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
  288. })
  289. })
  290. describe('When updating my avatar', function () {
  291. it('Should fail without an incorrect input file', async function () {
  292. const fields = {}
  293. const attaches = {
  294. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
  295. }
  296. await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
  297. })
  298. it('Should fail with a big file', async function () {
  299. const fields = {}
  300. const attaches = {
  301. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
  302. }
  303. await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
  304. })
  305. it('Should fail with an unauthenticated user', async function () {
  306. const fields = {}
  307. const attaches = {
  308. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
  309. }
  310. await makeUploadRequest({
  311. url: server.url,
  312. path: path + '/me/avatar/pick',
  313. fields,
  314. attaches,
  315. statusCodeExpected: 401
  316. })
  317. })
  318. it('Should succeed with the correct params', async function () {
  319. const fields = {}
  320. const attaches = {
  321. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
  322. }
  323. await makeUploadRequest({
  324. url: server.url,
  325. path: path + '/me/avatar/pick',
  326. token: server.accessToken,
  327. fields,
  328. attaches,
  329. statusCodeExpected: 200
  330. })
  331. })
  332. })
  333. describe('When getting a user', function () {
  334. before(async function () {
  335. const res = await getUsersList(server.url, server.accessToken)
  336. userId = res.body.data[1].id
  337. })
  338. it('Should fail with an non authenticated user', async function () {
  339. await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
  340. })
  341. it('Should fail with a non admin user', async function () {
  342. await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
  343. })
  344. it('Should succeed with the correct params', async function () {
  345. await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
  346. })
  347. })
  348. describe('When updating a user', function () {
  349. before(async function () {
  350. const res = await getUsersList(server.url, server.accessToken)
  351. userId = res.body.data[1].id
  352. rootId = res.body.data[2].id
  353. })
  354. it('Should fail with an invalid email attribute', async function () {
  355. const fields = {
  356. email: 'blabla'
  357. }
  358. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  359. })
  360. it('Should fail with an invalid emailVerified attribute', async function () {
  361. const fields = {
  362. emailVerified: 'yes'
  363. }
  364. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  365. })
  366. it('Should fail with an invalid videoQuota attribute', async function () {
  367. const fields = {
  368. videoQuota: -90
  369. }
  370. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  371. })
  372. it('Should fail with an invalid user role attribute', async function () {
  373. const fields = {
  374. role: 54878
  375. }
  376. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  377. })
  378. it('Should fail with a too small password', async function () {
  379. const fields = {
  380. currentPassword: 'my super password',
  381. password: 'bla'
  382. }
  383. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  384. })
  385. it('Should fail with a too long password', async function () {
  386. const fields = {
  387. currentPassword: 'my super password',
  388. password: 'super'.repeat(61)
  389. }
  390. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
  391. })
  392. it('Should fail with an non authenticated user', async function () {
  393. const fields = {
  394. videoQuota: 42
  395. }
  396. await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
  397. })
  398. it('Should fail when updating root role', async function () {
  399. const fields = {
  400. role: UserRole.MODERATOR
  401. }
  402. await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
  403. })
  404. it('Should fail with invalid admin flags', async function () {
  405. const fields = { adminFlags: 'toto' }
  406. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  407. })
  408. it('Should succeed with the correct params', async function () {
  409. const fields = {
  410. email: 'email@example.com',
  411. emailVerified: true,
  412. videoQuota: 42,
  413. role: UserRole.USER
  414. }
  415. await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
  416. })
  417. })
  418. describe('When getting my information', function () {
  419. it('Should fail with a non authenticated user', async function () {
  420. await getMyUserInformation(server.url, 'fake_token', 401)
  421. })
  422. it('Should success with the correct parameters', async function () {
  423. await getMyUserInformation(server.url, userAccessToken)
  424. })
  425. })
  426. describe('When getting my video rating', function () {
  427. it('Should fail with a non authenticated user', async function () {
  428. await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
  429. })
  430. it('Should fail with an incorrect video uuid', async function () {
  431. await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
  432. })
  433. it('Should fail with an unknown video', async function () {
  434. await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
  435. })
  436. it('Should succeed with the correct parameters', async function () {
  437. await getMyUserVideoRating(server.url, server.accessToken, videoId)
  438. })
  439. })
  440. describe('When retrieving my global ratings', function () {
  441. const path = '/api/v1/accounts/user1/ratings'
  442. it('Should fail with a bad start pagination', async function () {
  443. await checkBadStartPagination(server.url, path, userAccessToken)
  444. })
  445. it('Should fail with a bad count pagination', async function () {
  446. await checkBadCountPagination(server.url, path, userAccessToken)
  447. })
  448. it('Should fail with an incorrect sort', async function () {
  449. await checkBadSortPagination(server.url, path, userAccessToken)
  450. })
  451. it('Should fail with a unauthenticated user', async function () {
  452. await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
  453. })
  454. it('Should fail with a another user', async function () {
  455. await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
  456. })
  457. it('Should fail with a bad type', async function () {
  458. await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
  459. })
  460. it('Should succeed with the correct params', async function () {
  461. await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
  462. })
  463. })
  464. describe('When blocking/unblocking/removing user', function () {
  465. it('Should fail with an incorrect id', async function () {
  466. await removeUser(server.url, 'blabla', server.accessToken, 400)
  467. await blockUser(server.url, 'blabla', server.accessToken, 400)
  468. await unblockUser(server.url, 'blabla', server.accessToken, 400)
  469. })
  470. it('Should fail with the root user', async function () {
  471. await removeUser(server.url, rootId, server.accessToken, 400)
  472. await blockUser(server.url, rootId, server.accessToken, 400)
  473. await unblockUser(server.url, rootId, server.accessToken, 400)
  474. })
  475. it('Should return 404 with a non existing id', async function () {
  476. await removeUser(server.url, 4545454, server.accessToken, 404)
  477. await blockUser(server.url, 4545454, server.accessToken, 404)
  478. await unblockUser(server.url, 4545454, server.accessToken, 404)
  479. })
  480. it('Should fail with a non admin user', async function () {
  481. await removeUser(server.url, userId, userAccessToken, 403)
  482. await blockUser(server.url, userId, userAccessToken, 403)
  483. await unblockUser(server.url, userId, userAccessToken, 403)
  484. })
  485. })
  486. describe('When deleting our account', function () {
  487. it('Should fail with with the root account', async function () {
  488. await deleteMe(server.url, server.accessToken, 400)
  489. })
  490. })
  491. describe('When register a new user', function () {
  492. const registrationPath = path + '/register'
  493. const baseCorrectParams = {
  494. username: 'user3',
  495. email: 'test3@example.com',
  496. password: 'my super password'
  497. }
  498. it('Should fail with a too small username', async function () {
  499. const fields = immutableAssign(baseCorrectParams, { username: '' })
  500. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  501. })
  502. it('Should fail with a too long username', async function () {
  503. const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
  504. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  505. })
  506. it('Should fail with an incorrect username', async function () {
  507. const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
  508. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  509. })
  510. it('Should fail with a missing email', async function () {
  511. const fields = omit(baseCorrectParams, 'email')
  512. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  513. })
  514. it('Should fail with an invalid email', async function () {
  515. const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
  516. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  517. })
  518. it('Should fail with a too small password', async function () {
  519. const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
  520. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  521. })
  522. it('Should fail with a too long password', async function () {
  523. const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
  524. await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
  525. })
  526. it('Should fail if we register a user with the same username', async function () {
  527. const fields = immutableAssign(baseCorrectParams, { username: 'root' })
  528. await makePostBodyRequest({
  529. url: server.url,
  530. path: registrationPath,
  531. token: server.accessToken,
  532. fields,
  533. statusCodeExpected: 409
  534. })
  535. })
  536. it('Should fail with a "peertube" username', async function () {
  537. const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
  538. await makePostBodyRequest({
  539. url: server.url,
  540. path: registrationPath,
  541. token: server.accessToken,
  542. fields,
  543. statusCodeExpected: 409
  544. })
  545. })
  546. it('Should fail if we register a user with the same email', async function () {
  547. const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' })
  548. await makePostBodyRequest({
  549. url: server.url,
  550. path: registrationPath,
  551. token: server.accessToken,
  552. fields,
  553. statusCodeExpected: 409
  554. })
  555. })
  556. it('Should succeed with the correct params', async function () {
  557. await makePostBodyRequest({
  558. url: server.url,
  559. path: registrationPath,
  560. token: server.accessToken,
  561. fields: baseCorrectParams,
  562. statusCodeExpected: 204
  563. })
  564. })
  565. it('Should fail on a server with registration disabled', async function () {
  566. const fields = {
  567. username: 'user4',
  568. email: 'test4@example.com',
  569. password: 'my super password 4'
  570. }
  571. await makePostBodyRequest({
  572. url: serverWithRegistrationDisabled.url,
  573. path: registrationPath,
  574. token: serverWithRegistrationDisabled.accessToken,
  575. fields,
  576. statusCodeExpected: 403
  577. })
  578. })
  579. })
  580. describe('When registering multiple users on a server with users limit', function () {
  581. it('Should fail when after 3 registrations', async function () {
  582. await registerUser(server.url, 'user42', 'super password', 403)
  583. })
  584. })
  585. describe('When having a video quota', function () {
  586. it('Should fail with a user having too many videos', async function () {
  587. await updateUser({
  588. url: server.url,
  589. userId: rootId,
  590. accessToken: server.accessToken,
  591. videoQuota: 42
  592. })
  593. await uploadVideo(server.url, server.accessToken, {}, 403)
  594. })
  595. it('Should fail with a registered user having too many videos', async function () {
  596. this.timeout(30000)
  597. const user = {
  598. username: 'user3',
  599. password: 'my super password'
  600. }
  601. userAccessToken = await userLogin(server, user)
  602. const videoAttributes = { fixture: 'video_short2.webm' }
  603. await uploadVideo(server.url, userAccessToken, videoAttributes)
  604. await uploadVideo(server.url, userAccessToken, videoAttributes)
  605. await uploadVideo(server.url, userAccessToken, videoAttributes)
  606. await uploadVideo(server.url, userAccessToken, videoAttributes)
  607. await uploadVideo(server.url, userAccessToken, videoAttributes)
  608. await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
  609. })
  610. it('Should fail to import with HTTP/Torrent/magnet', async function () {
  611. this.timeout(120000)
  612. const baseAttributes = {
  613. channelId: 1,
  614. privacy: VideoPrivacy.PUBLIC
  615. }
  616. await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
  617. await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
  618. await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
  619. await waitJobs([ server ])
  620. const res = await getMyVideoImports(server.url, server.accessToken)
  621. expect(res.body.total).to.equal(3)
  622. const videoImports: VideoImport[] = res.body.data
  623. expect(videoImports).to.have.lengthOf(3)
  624. for (const videoImport of videoImports) {
  625. expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
  626. expect(videoImport.error).not.to.be.undefined
  627. expect(videoImport.error).to.contain('user video quota is exceeded')
  628. }
  629. })
  630. })
  631. describe('When having a daily video quota', function () {
  632. it('Should fail with a user having too many videos', async function () {
  633. await updateUser({
  634. url: server.url,
  635. userId: rootId,
  636. accessToken: server.accessToken,
  637. videoQuotaDaily: 42
  638. })
  639. await uploadVideo(server.url, server.accessToken, {}, 403)
  640. })
  641. })
  642. describe('When having an absolute and daily video quota', function () {
  643. it('Should fail if exceeding total quota', async function () {
  644. await updateUser({
  645. url: server.url,
  646. userId: rootId,
  647. accessToken: server.accessToken,
  648. videoQuota: 42,
  649. videoQuotaDaily: 1024 * 1024 * 1024
  650. })
  651. await uploadVideo(server.url, server.accessToken, {}, 403)
  652. })
  653. it('Should fail if exceeding daily quota', async function () {
  654. await updateUser({
  655. url: server.url,
  656. userId: rootId,
  657. accessToken: server.accessToken,
  658. videoQuota: 1024 * 1024 * 1024,
  659. videoQuotaDaily: 42
  660. })
  661. await uploadVideo(server.url, server.accessToken, {}, 403)
  662. })
  663. })
  664. describe('When asking a password reset', function () {
  665. const path = '/api/v1/users/ask-reset-password'
  666. it('Should fail with a missing email', async function () {
  667. const fields = {}
  668. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  669. })
  670. it('Should fail with an invalid email', async function () {
  671. const fields = { email: 'hello' }
  672. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  673. })
  674. it('Should success with the correct params', async function () {
  675. const fields = { email: 'admin@example.com' }
  676. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
  677. })
  678. })
  679. describe('When asking for an account verification email', function () {
  680. const path = '/api/v1/users/ask-send-verify-email'
  681. it('Should fail with a missing email', async function () {
  682. const fields = {}
  683. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  684. })
  685. it('Should fail with an invalid email', async function () {
  686. const fields = { email: 'hello' }
  687. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  688. })
  689. it('Should succeed with the correct params', async function () {
  690. const fields = { email: 'admin@example.com' }
  691. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
  692. })
  693. })
  694. after(function () {
  695. killallServers([ server, serverWithRegistrationDisabled ])
  696. })
  697. })