X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Ffollows.ts;h=3c911dcee820341ae4ea990de465be7558a8eb97;hb=8d1f78044ca6eb9995001d3ab83be62460e043a6;hp=dfe3f226d4e075a5708e6835f768ba598599c912;hpb=c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index dfe3f226d..3c911dcee 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -1,10 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeDeleteRequest, @@ -12,8 +10,7 @@ import { makePostBodyRequest, PeerTubeServer, setAccessTokensToServers -} from '@shared/extra-utils' -import { HttpStatusCode } from '@shared/models' +} from '@shared/server-commands' describe('Test server follows API validators', function () { let server: PeerTubeServer @@ -32,19 +29,13 @@ describe('Test server follows API validators', function () { let userAccessToken = null before(async function () { - const user = { - username: 'user1', - password: 'password' - } - - await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.login.getAccessToken(user) + userAccessToken = await server.users.generateUserAndToken('user1') }) describe('When adding follows', function () { const path = '/api/v1/server/following' - it('Should fail without hosts', async function () { + it('Should fail with nothing', async function () { await makePostBodyRequest({ url: server.url, path, @@ -53,41 +44,51 @@ describe('Test server follows API validators', function () { }) }) - it('Should fail if hosts is not an array', async function () { + it('Should fail if hosts is not composed by hosts', async function () { await makePostBodyRequest({ url: server.url, path, + fields: { hosts: [ '127.0.0.1:9002', '127.0.0.1:coucou' ] }, token: server.accessToken, - fields: { hosts: 'localhost:9002' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if the array is not composed by hosts', async function () { + it('Should fail if hosts is composed with http schemes', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, + fields: { hosts: [ '127.0.0.1:9002', 'http://127.0.0.1:9003' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if the array is composed with http schemes', async function () { + it('Should fail if hosts are not unique', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, + fields: { urls: [ '127.0.0.1:9002', '127.0.0.1:9002' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if hosts are not unique', async function () { + it('Should fail if handles is not composed by handles', async function () { + await makePostBodyRequest({ + url: server.url, + path, + fields: { handles: [ 'hello@example.com', '127.0.0.1:9001' ] }, + token: server.accessToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail if handles are not unique', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, + fields: { urls: [ 'hello@example.com', 'hello@example.com' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) @@ -97,7 +98,7 @@ describe('Test server follows API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002' ] }, + fields: { hosts: [ '127.0.0.1:9002' ] }, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -107,7 +108,7 @@ describe('Test server follows API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002' ] }, + fields: { hosts: [ '127.0.0.1:9002' ] }, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) @@ -216,7 +217,7 @@ describe('Test server follows API validators', function () { it('Should fail with an invalid token', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/toto@localhost:9002', + path: path + '/toto@127.0.0.1:9002', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -225,7 +226,7 @@ describe('Test server follows API validators', function () { it('Should fail if the user is not an administrator', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/toto@localhost:9002', + path: path + '/toto@127.0.0.1:9002', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) @@ -243,7 +244,7 @@ describe('Test server follows API validators', function () { it('Should fail with an unknown follower', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/toto@localhost:9003', + path: path + '/toto@127.0.0.1:9003', token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) @@ -256,7 +257,7 @@ describe('Test server follows API validators', function () { it('Should fail with an invalid token', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9002/accept', + path: path + '/toto@127.0.0.1:9002/accept', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -265,7 +266,7 @@ describe('Test server follows API validators', function () { it('Should fail if the user is not an administrator', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9002/accept', + path: path + '/toto@127.0.0.1:9002/accept', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) @@ -283,7 +284,7 @@ describe('Test server follows API validators', function () { it('Should fail with an unknown follower', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9003/accept', + path: path + '/toto@127.0.0.1:9003/accept', token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) @@ -296,7 +297,7 @@ describe('Test server follows API validators', function () { it('Should fail with an invalid token', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9002/reject', + path: path + '/toto@127.0.0.1:9002/reject', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -305,7 +306,7 @@ describe('Test server follows API validators', function () { it('Should fail if the user is not an administrator', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9002/reject', + path: path + '/toto@127.0.0.1:9002/reject', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) @@ -323,7 +324,7 @@ describe('Test server follows API validators', function () { it('Should fail with an unknown follower', async function () { await makePostBodyRequest({ url: server.url, - path: path + '/toto@localhost:9003/reject', + path: path + '/toto@127.0.0.1:9003/reject', token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) @@ -336,7 +337,7 @@ describe('Test server follows API validators', function () { it('Should fail with an invalid token', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/localhost:9002', + path: path + '/127.0.0.1:9002', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -345,7 +346,7 @@ describe('Test server follows API validators', function () { it('Should fail if the user is not an administrator', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/localhost:9002', + path: path + '/127.0.0.1:9002', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })