diff options
Diffstat (limited to 'server/tests/api/check-params/users.js')
-rw-r--r-- | server/tests/api/check-params/users.js | 127 |
1 files changed, 125 insertions, 2 deletions
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js index 4a176e6c2..0aa9a4524 100644 --- a/server/tests/api/check-params/users.js +++ b/server/tests/api/check-params/users.js | |||
@@ -17,6 +17,7 @@ describe('Test users API validators', function () { | |||
17 | let rootId = null | 17 | let rootId = null |
18 | let videoId = null | 18 | let videoId = null |
19 | let server = null | 19 | let server = null |
20 | let serverWithRegistrationDisabled = null | ||
20 | let userAccessToken = null | 21 | let userAccessToken = null |
21 | 22 | ||
22 | // --------------------------------------------------------------- | 23 | // --------------------------------------------------------------- |
@@ -29,8 +30,15 @@ describe('Test users API validators', function () { | |||
29 | serversUtils.flushTests(next) | 30 | serversUtils.flushTests(next) |
30 | }, | 31 | }, |
31 | function (next) { | 32 | function (next) { |
32 | serversUtils.runServer(1, function (server1) { | 33 | serversUtils.runServer(1, function (serverCreated) { |
33 | server = server1 | 34 | server = serverCreated |
35 | |||
36 | next() | ||
37 | }) | ||
38 | }, | ||
39 | function (next) { | ||
40 | serversUtils.runServer(2, function (serverCreated) { | ||
41 | serverWithRegistrationDisabled = serverCreated | ||
34 | 42 | ||
35 | next() | 43 | next() |
36 | }) | 44 | }) |
@@ -394,6 +402,121 @@ describe('Test users API validators', function () { | |||
394 | }) | 402 | }) |
395 | }) | 403 | }) |
396 | 404 | ||
405 | describe('When register a new user', function () { | ||
406 | const registrationPath = path + '/register' | ||
407 | |||
408 | it('Should fail with a too small username', function (done) { | ||
409 | const data = { | ||
410 | username: 'ji', | ||
411 | email: 'test@example.com', | ||
412 | password: 'mysuperpassword' | ||
413 | } | ||
414 | |||
415 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
416 | }) | ||
417 | |||
418 | it('Should fail with a too long username', function (done) { | ||
419 | const data = { | ||
420 | username: 'mysuperusernamewhichisverylong', | ||
421 | email: 'test@example.com', | ||
422 | password: 'mysuperpassword' | ||
423 | } | ||
424 | |||
425 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
426 | }) | ||
427 | |||
428 | it('Should fail with an incorrect username', function (done) { | ||
429 | const data = { | ||
430 | username: 'my username', | ||
431 | email: 'test@example.com', | ||
432 | password: 'mysuperpassword' | ||
433 | } | ||
434 | |||
435 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
436 | }) | ||
437 | |||
438 | it('Should fail with a missing email', function (done) { | ||
439 | const data = { | ||
440 | username: 'ji', | ||
441 | password: 'mysuperpassword' | ||
442 | } | ||
443 | |||
444 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
445 | }) | ||
446 | |||
447 | it('Should fail with an invalid email', function (done) { | ||
448 | const data = { | ||
449 | username: 'mysuperusernamewhichisverylong', | ||
450 | email: 'testexample.com', | ||
451 | password: 'mysuperpassword' | ||
452 | } | ||
453 | |||
454 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
455 | }) | ||
456 | |||
457 | it('Should fail with a too small password', function (done) { | ||
458 | const data = { | ||
459 | username: 'myusername', | ||
460 | email: 'test@example.com', | ||
461 | password: 'bla' | ||
462 | } | ||
463 | |||
464 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
465 | }) | ||
466 | |||
467 | it('Should fail with a too long password', function (done) { | ||
468 | const data = { | ||
469 | username: 'myusername', | ||
470 | email: 'test@example.com', | ||
471 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
472 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
473 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
474 | } | ||
475 | |||
476 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done) | ||
477 | }) | ||
478 | |||
479 | it('Should fail if we register a user with the same username', function (done) { | ||
480 | const data = { | ||
481 | username: 'root', | ||
482 | email: 'test@example.com', | ||
483 | password: 'my super password' | ||
484 | } | ||
485 | |||
486 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 409) | ||
487 | }) | ||
488 | |||
489 | it('Should fail if we register a user with the same email', function (done) { | ||
490 | const data = { | ||
491 | username: 'myusername', | ||
492 | email: 'admin1@example.com', | ||
493 | password: 'my super password' | ||
494 | } | ||
495 | |||
496 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 409) | ||
497 | }) | ||
498 | |||
499 | it('Should succeed with the correct params', function (done) { | ||
500 | const data = { | ||
501 | username: 'user3', | ||
502 | email: 'test3@example.com', | ||
503 | password: 'my super password' | ||
504 | } | ||
505 | |||
506 | requestsUtils.makePostBodyRequest(server.url, registrationPath, server.accessToken, data, done, 204) | ||
507 | }) | ||
508 | |||
509 | it('Should fail on a server with registration disabled', function (done) { | ||
510 | const data = { | ||
511 | username: 'user4', | ||
512 | email: 'test4@example.com', | ||
513 | password: 'my super password 4' | ||
514 | } | ||
515 | |||
516 | requestsUtils.makePostBodyRequest(serverWithRegistrationDisabled.url, registrationPath, serverWithRegistrationDisabled.accessToken, data, done, 400) | ||
517 | }) | ||
518 | }) | ||
519 | |||
397 | after(function (done) { | 520 | after(function (done) { |
398 | process.kill(-server.app.pid) | 521 | process.kill(-server.app.pid) |
399 | 522 | ||