mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Merge branch 'develop' into pr/1217
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import { flushTests, killallServers, runServer, ServerInfo } from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getAccount } from '../../utils/users/accounts'
|
||||
import { flushTests, killallServers, runServer, ServerInfo } from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { getAccount } from '../../../../shared/utils/users/accounts'
|
||||
|
||||
describe('Test users API validators', function () {
|
||||
describe('Test accounts API validators', function () {
|
||||
const path = '/api/v1/accounts/'
|
||||
let server: ServerInfo
|
||||
|
||||
|
||||
498
server/tests/api/check-params/blocklist.ts
Normal file
498
server/tests/api/check-params/blocklist.ts
Normal file
@@ -0,0 +1,498 @@
|
||||
/* tslint:disable:no-unused-expression */
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import {
|
||||
createUser,
|
||||
doubleFollow,
|
||||
flushAndRunMultipleServers,
|
||||
flushTests,
|
||||
killallServers,
|
||||
makeDeleteRequest,
|
||||
makeGetRequest,
|
||||
makePostBodyRequest,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers, userLogin
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
|
||||
describe('Test blocklist API validators', function () {
|
||||
let servers: ServerInfo[]
|
||||
let server: ServerInfo
|
||||
let userAccessToken: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await flushTests()
|
||||
|
||||
servers = await flushAndRunMultipleServers(2)
|
||||
await setAccessTokensToServers(servers)
|
||||
|
||||
server = servers[0]
|
||||
|
||||
const user = { username: 'user1', password: 'password' }
|
||||
await createUser(server.url, server.accessToken, user.username, user.password)
|
||||
|
||||
userAccessToken = await userLogin(server, user)
|
||||
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
describe('When managing user blocklist', function () {
|
||||
|
||||
describe('When managing user accounts blocklist', function () {
|
||||
const path = '/api/v1/users/me/blocklist/accounts'
|
||||
|
||||
describe('When listing blocked accounts', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When blocking an account', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: { accountName: 'user1' },
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown account', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'user2' },
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail to block ourselves', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'root' },
|
||||
statusCodeExpected: 409
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'user1' },
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unblocking an account', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user1',
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown account block', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user2',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user1',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When managing user servers blocklist', function () {
|
||||
const path = '/api/v1/users/me/blocklist/servers'
|
||||
|
||||
describe('When listing blocked servers', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When blocking a server', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: { host: 'localhost:9002' },
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown server', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9003' },
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with our own server', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9001' },
|
||||
statusCodeExpected: 409
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9002' },
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unblocking a server', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9002',
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown server block', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9003',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9002',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When managing server blocklist', function () {
|
||||
|
||||
describe('When managing server accounts blocklist', function () {
|
||||
const path = '/api/v1/server/blocklist/accounts'
|
||||
|
||||
describe('When listing blocked accounts', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
token: userAccessToken,
|
||||
path,
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When blocking an account', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: { accountName: 'user1' },
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: userAccessToken,
|
||||
path,
|
||||
fields: { accountName: 'user1' },
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown account', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'user2' },
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail to block ourselves', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'root' },
|
||||
statusCodeExpected: 409
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { accountName: 'user1' },
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unblocking an account', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user1',
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user1',
|
||||
token: userAccessToken,
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown account block', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user2',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/user1',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When managing server servers blocklist', function () {
|
||||
const path = '/api/v1/server/blocklist/servers'
|
||||
|
||||
describe('When listing blocked servers', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
token: userAccessToken,
|
||||
path,
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When blocking a server', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: { host: 'localhost:9002' },
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: userAccessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9002' },
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown server', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9003' },
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with our own server', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9001' },
|
||||
statusCodeExpected: 409
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path,
|
||||
fields: { host: 'localhost:9002' },
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unblocking a server', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9002',
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a user without the appropriate rights', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9002',
|
||||
token: userAccessToken,
|
||||
statusCodeExpected: 403
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an unknown server block', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9003',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 404
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makeDeleteRequest({
|
||||
url: server.url,
|
||||
path: path + '/localhost:9002',
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
killallServers(servers)
|
||||
|
||||
// Keep the logs if the test failed
|
||||
if (this['ok']) {
|
||||
await flushTests()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -7,7 +7,7 @@ import { CustomConfig } from '../../../../shared/models/server/custom-config.mod
|
||||
import {
|
||||
createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
|
||||
setAccessTokensToServers, userLogin, immutableAssign
|
||||
} from '../../utils'
|
||||
} from '../../../../shared/utils'
|
||||
|
||||
describe('Test config API validators', function () {
|
||||
const path = '/api/v1/config/custom'
|
||||
@@ -48,12 +48,16 @@ describe('Test config API validators', function () {
|
||||
admin: {
|
||||
email: 'superadmin1@example.com'
|
||||
},
|
||||
contactForm: {
|
||||
enabled: false
|
||||
},
|
||||
user: {
|
||||
videoQuota: 5242881,
|
||||
videoQuotaDaily: 318742
|
||||
},
|
||||
transcoding: {
|
||||
enabled: true,
|
||||
allowAdditionalExtensions: true,
|
||||
threads: 1,
|
||||
resolutions: {
|
||||
'240p': false,
|
||||
@@ -61,6 +65,9 @@ describe('Test config API validators', function () {
|
||||
'480p': true,
|
||||
'720p': false,
|
||||
'1080p': false
|
||||
},
|
||||
hls: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
import: {
|
||||
|
||||
96
server/tests/api/check-params/contact-form.ts
Normal file
96
server/tests/api/check-params/contact-form.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
/* tslint:disable:no-unused-expression */
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import {
|
||||
flushTests,
|
||||
immutableAssign,
|
||||
killallServers,
|
||||
reRunServer,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { getAccount } from '../../../../shared/utils/users/accounts'
|
||||
import { sendContactForm } from '../../../../shared/utils/server/contact-form'
|
||||
import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
|
||||
|
||||
describe('Test contact form API validators', function () {
|
||||
let server: ServerInfo
|
||||
const emails: object[] = []
|
||||
const defaultBody = {
|
||||
fromName: 'super name',
|
||||
fromEmail: 'toto@example.com',
|
||||
body: 'Hello, how are you?'
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await flushTests()
|
||||
await MockSmtpServer.Instance.collectEmails(emails)
|
||||
|
||||
// Email is disabled
|
||||
server = await runServer(1)
|
||||
})
|
||||
|
||||
it('Should not accept a contact form if emails are disabled', async function () {
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
|
||||
})
|
||||
|
||||
it('Should not accept a contact form if it is disabled in the configuration', async function () {
|
||||
this.timeout(10000)
|
||||
|
||||
killallServers([ server ])
|
||||
|
||||
// Contact form is disabled
|
||||
await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } })
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
|
||||
})
|
||||
|
||||
it('Should not accept a contact form if from email is invalid', async function () {
|
||||
this.timeout(10000)
|
||||
|
||||
killallServers([ server ])
|
||||
|
||||
// Email & contact form enabled
|
||||
await reRunServer(server, { smtp: { hostname: 'localhost' } })
|
||||
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
|
||||
})
|
||||
|
||||
it('Should not accept a contact form if from name is invalid', async function () {
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
|
||||
})
|
||||
|
||||
it('Should not accept a contact form if body is invalid', async function () {
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
|
||||
})
|
||||
|
||||
it('Should accept a contact form with the correct parameters', async function () {
|
||||
await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
MockSmtpServer.Instance.kill()
|
||||
killallServers([ server ])
|
||||
|
||||
// Keep the logs if the test failed
|
||||
if (this['ok']) {
|
||||
await flushTests()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -5,8 +5,12 @@ import 'mocha'
|
||||
import {
|
||||
createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
|
||||
describe('Test server follows API validators', function () {
|
||||
let server: ServerInfo
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// Order of the tests we want to execute
|
||||
import './accounts'
|
||||
import './blocklist'
|
||||
import './config'
|
||||
import './contact-form'
|
||||
import './follows'
|
||||
import './jobs'
|
||||
import './redundancy'
|
||||
import './search'
|
||||
import './services'
|
||||
import './user-notifications'
|
||||
import './user-subscriptions'
|
||||
import './users'
|
||||
import './video-abuses'
|
||||
@@ -15,4 +17,5 @@ import './video-channels'
|
||||
import './video-comments'
|
||||
import './video-imports'
|
||||
import './videos'
|
||||
import './videos-filter'
|
||||
import './videos-history'
|
||||
|
||||
@@ -2,9 +2,21 @@
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import { createUser, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { makeGetRequest } from '../../utils/requests/requests'
|
||||
import {
|
||||
createUser,
|
||||
flushTests,
|
||||
killallServers,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { makeGetRequest } from '../../../../shared/utils/requests/requests'
|
||||
|
||||
describe('Test jobs API validators', function () {
|
||||
const path = '/api/v1/jobs/failed'
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
} from '../../../../shared/utils'
|
||||
|
||||
describe('Test server redundancy API validators', function () {
|
||||
let servers: ServerInfo[]
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
|
||||
describe('Test videos API validator', function () {
|
||||
let server: ServerInfo
|
||||
|
||||
@@ -2,7 +2,15 @@
|
||||
|
||||
import 'mocha'
|
||||
|
||||
import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
|
||||
import {
|
||||
flushTests,
|
||||
killallServers,
|
||||
makeGetRequest,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
uploadVideo
|
||||
} from '../../../../shared/utils'
|
||||
|
||||
describe('Test services API validators', function () {
|
||||
let server: ServerInfo
|
||||
|
||||
297
server/tests/api/check-params/user-notifications.ts
Normal file
297
server/tests/api/check-params/user-notifications.ts
Normal file
@@ -0,0 +1,297 @@
|
||||
/* tslint:disable:no-unused-expression */
|
||||
|
||||
import 'mocha'
|
||||
import * as io from 'socket.io-client'
|
||||
|
||||
import {
|
||||
flushTests,
|
||||
immutableAssign,
|
||||
killallServers,
|
||||
makeGetRequest,
|
||||
makePostBodyRequest,
|
||||
makePutBodyRequest,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
wait
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
|
||||
|
||||
describe('Test user notifications API validators', function () {
|
||||
let server: ServerInfo
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await flushTests()
|
||||
|
||||
server = await runServer(1)
|
||||
|
||||
await setAccessTokensToServers([ server ])
|
||||
})
|
||||
|
||||
describe('When listing my notifications', function () {
|
||||
const path = '/api/v1/users/me/notifications'
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, path, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect unread parameter', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
query: {
|
||||
unread: 'toto'
|
||||
},
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When marking as read my notifications', function () {
|
||||
const path = '/api/v1/users/me/notifications/read'
|
||||
|
||||
it('Should fail with wrong ids parameters', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: {
|
||||
ids: [ 'hello' ]
|
||||
},
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: {
|
||||
ids: [ ]
|
||||
},
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: {
|
||||
ids: 5
|
||||
},
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: {
|
||||
ids: [ 5 ]
|
||||
},
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: {
|
||||
ids: [ 5 ]
|
||||
},
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When marking as read my notifications', function () {
|
||||
const path = '/api/v1/users/me/notifications/read-all'
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When updating my notification settings', function () {
|
||||
const path = '/api/v1/users/me/notification-settings'
|
||||
const correctFields: UserNotificationSetting = {
|
||||
newVideoFromSubscription: UserNotificationSettingValue.WEB,
|
||||
newCommentOnMyVideo: UserNotificationSettingValue.WEB,
|
||||
videoAbuseAsModerator: UserNotificationSettingValue.WEB,
|
||||
blacklistOnMyVideo: UserNotificationSettingValue.WEB,
|
||||
myVideoImportFinished: UserNotificationSettingValue.WEB,
|
||||
myVideoPublished: UserNotificationSettingValue.WEB,
|
||||
commentMention: UserNotificationSettingValue.WEB,
|
||||
newFollow: UserNotificationSettingValue.WEB,
|
||||
newUserRegistration: UserNotificationSettingValue.WEB
|
||||
}
|
||||
|
||||
it('Should fail with missing fields', async function () {
|
||||
await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token: server.accessToken,
|
||||
fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB },
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with incorrect field values', async function () {
|
||||
{
|
||||
const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 })
|
||||
|
||||
await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token: server.accessToken,
|
||||
fields,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' })
|
||||
|
||||
await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields,
|
||||
token: server.accessToken,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: correctFields,
|
||||
statusCodeExpected: 401
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token: server.accessToken,
|
||||
fields: correctFields,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('When connecting to my notification socket', function () {
|
||||
it('Should fail with no token', function (next) {
|
||||
const socket = io('http://localhost:9001/user-notifications', { reconnection: false })
|
||||
|
||||
socket.on('error', () => {
|
||||
socket.removeListener('error', this)
|
||||
socket.disconnect()
|
||||
next()
|
||||
})
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.disconnect()
|
||||
next(new Error('Connected with a missing token.'))
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with an invalid token', function (next) {
|
||||
const socket = io('http://localhost:9001/user-notifications', {
|
||||
query: { accessToken: 'bad_access_token' },
|
||||
reconnection: false
|
||||
})
|
||||
|
||||
socket.on('error', () => {
|
||||
socket.removeListener('error', this)
|
||||
socket.disconnect()
|
||||
next()
|
||||
})
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.disconnect()
|
||||
next(new Error('Connected with an invalid token.'))
|
||||
})
|
||||
})
|
||||
|
||||
it('Should success with the correct token', function (next) {
|
||||
const socket = io('http://localhost:9001/user-notifications', {
|
||||
query: { accessToken: server.accessToken },
|
||||
reconnection: false
|
||||
})
|
||||
|
||||
const errorListener = socket.on('error', err => {
|
||||
next(new Error('Error in connection: ' + err))
|
||||
})
|
||||
|
||||
socket.on('connect', async () => {
|
||||
socket.removeListener('error', errorListener)
|
||||
socket.disconnect()
|
||||
|
||||
await wait(500)
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
killallServers([ server ])
|
||||
|
||||
// Keep the logs if the test failed
|
||||
if (this['ok']) {
|
||||
await flushTests()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -13,8 +13,14 @@ import {
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
} from '../../../../shared/utils'
|
||||
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
||||
|
||||
describe('Test user subscriptions API validators', function () {
|
||||
const path = '/api/v1/users/me/subscriptions'
|
||||
@@ -141,6 +147,8 @@ describe('Test user subscriptions API validators', function () {
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
this.timeout(20000)
|
||||
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
@@ -148,6 +156,8 @@ describe('Test user subscriptions API validators', function () {
|
||||
fields: { uri: 'user1_channel@localhost:9001' },
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
|
||||
await waitJobs([ server ])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -9,11 +9,15 @@ import {
|
||||
createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
|
||||
makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers,
|
||||
updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports'
|
||||
import { VideoPrivacy } from '../../../../shared/models/videos'
|
||||
import { waitJobs } from '../../utils/server/jobs'
|
||||
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test users API validators', function () {
|
||||
@@ -99,13 +103,13 @@ describe('Test users API validators', function () {
|
||||
}
|
||||
|
||||
it('Should fail with a too small username', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'fi' })
|
||||
const fields = immutableAssign(baseCorrectParams, { username: '' })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a too long username', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' })
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
@@ -304,6 +308,14 @@ describe('Test users API validators', function () {
|
||||
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
|
||||
const fields = {
|
||||
videosHistoryEnabled: -1
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with an non authenticated user', async function () {
|
||||
const fields = {
|
||||
currentPassword: 'my super password',
|
||||
@@ -315,7 +327,7 @@ describe('Test users API validators', function () {
|
||||
|
||||
it('Should fail with a too long description', async function () {
|
||||
const fields = {
|
||||
description: 'super'.repeat(60)
|
||||
description: 'super'.repeat(201)
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
|
||||
@@ -428,6 +440,14 @@ describe('Test users API validators', function () {
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid emailVerified attribute', async function () {
|
||||
const fields = {
|
||||
emailVerified: 'yes'
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid videoQuota attribute', async function () {
|
||||
const fields = {
|
||||
videoQuota: -90
|
||||
@@ -444,6 +464,24 @@ describe('Test users API validators', function () {
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a too small password', async function () {
|
||||
const fields = {
|
||||
currentPassword: 'my super password',
|
||||
password: 'bla'
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a too long password', async function () {
|
||||
const fields = {
|
||||
currentPassword: 'my super password',
|
||||
password: 'super'.repeat(61)
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with an non authenticated user', async function () {
|
||||
const fields = {
|
||||
videoQuota: 42
|
||||
@@ -463,12 +501,12 @@ describe('Test users API validators', function () {
|
||||
it('Should succeed with the correct params', async function () {
|
||||
const fields = {
|
||||
email: 'email@example.com',
|
||||
emailVerified: true,
|
||||
videoQuota: 42,
|
||||
role: UserRole.MODERATOR
|
||||
role: UserRole.USER
|
||||
}
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
|
||||
userAccessToken = await userLogin(server, user)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -541,13 +579,13 @@ describe('Test users API validators', function () {
|
||||
}
|
||||
|
||||
it('Should fail with a too small username', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'ji' })
|
||||
const fields = immutableAssign(baseCorrectParams, { username: '' })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a too long username', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' })
|
||||
const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
@@ -15,8 +15,12 @@ import {
|
||||
updateVideoAbuse,
|
||||
uploadVideo,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { VideoAbuseState } from '../../../../shared/models/videos'
|
||||
|
||||
describe('Test video abuses API validators', function () {
|
||||
@@ -109,8 +113,8 @@ describe('Test video abuses API validators', function () {
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a reason too big', async function () {
|
||||
const fields = { reason: 'super'.repeat(61) }
|
||||
it('Should fail with a too big reason', async function () {
|
||||
const fields = { reason: 'super'.repeat(605) }
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
@@ -150,7 +154,7 @@ describe('Test video abuses API validators', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a bad moderation comment', async function () {
|
||||
const body = { moderationComment: 'b'.repeat(305) }
|
||||
const body = { moderationComment: 'b'.repeat(3001) }
|
||||
await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
|
||||
})
|
||||
|
||||
|
||||
@@ -4,25 +4,33 @@ import 'mocha'
|
||||
|
||||
import {
|
||||
createUser,
|
||||
doubleFollow,
|
||||
flushAndRunMultipleServers,
|
||||
flushTests,
|
||||
getBlacklistedVideosList, getVideo, getVideoWithToken,
|
||||
getBlacklistedVideosList,
|
||||
getVideo,
|
||||
getVideoWithToken,
|
||||
killallServers,
|
||||
makePostBodyRequest,
|
||||
makePutBodyRequest,
|
||||
removeVideoFromBlacklist,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
uploadVideo,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
userLogin, waitJobs
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { VideoDetails } from '../../../../shared/models/videos'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test video blacklist API validators', function () {
|
||||
let server: ServerInfo
|
||||
let servers: ServerInfo[]
|
||||
let notBlacklistedVideoId: number
|
||||
let remoteVideoUUID: string
|
||||
let userAccessToken1 = ''
|
||||
let userAccessToken2 = ''
|
||||
|
||||
@@ -32,75 +40,89 @@ describe('Test video blacklist API validators', function () {
|
||||
this.timeout(120000)
|
||||
|
||||
await flushTests()
|
||||
servers = await flushAndRunMultipleServers(2)
|
||||
|
||||
server = await runServer(1)
|
||||
|
||||
await setAccessTokensToServers([ server ])
|
||||
await setAccessTokensToServers(servers)
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
|
||||
{
|
||||
const username = 'user1'
|
||||
const password = 'my super password'
|
||||
await createUser(server.url, server.accessToken, username, password)
|
||||
userAccessToken1 = await userLogin(server, { username, password })
|
||||
await createUser(servers[0].url, servers[0].accessToken, username, password)
|
||||
userAccessToken1 = await userLogin(servers[0], { username, password })
|
||||
}
|
||||
|
||||
{
|
||||
const username = 'user2'
|
||||
const password = 'my super password'
|
||||
await createUser(server.url, server.accessToken, username, password)
|
||||
userAccessToken2 = await userLogin(server, { username, password })
|
||||
await createUser(servers[0].url, servers[0].accessToken, username, password)
|
||||
userAccessToken2 = await userLogin(servers[0], { username, password })
|
||||
}
|
||||
|
||||
{
|
||||
const res = await uploadVideo(server.url, userAccessToken1, {})
|
||||
server.video = res.body.video
|
||||
const res = await uploadVideo(servers[0].url, userAccessToken1, {})
|
||||
servers[0].video = res.body.video
|
||||
}
|
||||
|
||||
{
|
||||
const res = await uploadVideo(server.url, server.accessToken, {})
|
||||
const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
|
||||
notBlacklistedVideoId = res.body.video.uuid
|
||||
}
|
||||
|
||||
{
|
||||
const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
|
||||
remoteVideoUUID = res.body.video.uuid
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
describe('When adding a video in blacklist', function () {
|
||||
const basePath = '/api/v1/videos/'
|
||||
|
||||
it('Should fail with nothing', async function () {
|
||||
const path = basePath + server.video + '/blacklist'
|
||||
const path = basePath + servers[0].video + '/blacklist'
|
||||
const fields = {}
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a wrong video', async function () {
|
||||
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
||||
const fields = {}
|
||||
await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
|
||||
await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
const path = basePath + server.video + '/blacklist'
|
||||
const path = basePath + servers[0].video + '/blacklist'
|
||||
const fields = {}
|
||||
await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||
})
|
||||
|
||||
it('Should fail with a non admin user', async function () {
|
||||
const path = basePath + server.video + '/blacklist'
|
||||
const path = basePath + servers[0].video + '/blacklist'
|
||||
const fields = {}
|
||||
await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid reason', async function () {
|
||||
const path = basePath + server.video.uuid + '/blacklist'
|
||||
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||
const fields = { reason: 'a'.repeat(305) }
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail to unfederate a remote video', async function () {
|
||||
const path = basePath + remoteVideoUUID + '/blacklist'
|
||||
const fields = { unfederate: true }
|
||||
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
const path = basePath + server.video.uuid + '/blacklist'
|
||||
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||
const fields = { }
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
|
||||
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -110,61 +132,61 @@ describe('Test video blacklist API validators', function () {
|
||||
it('Should fail with a wrong video', async function () {
|
||||
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
||||
const fields = {}
|
||||
await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
|
||||
await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a video not blacklisted', async function () {
|
||||
const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
|
||||
const fields = {}
|
||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
|
||||
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
|
||||
})
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
const path = basePath + server.video + '/blacklist'
|
||||
const path = basePath + servers[0].video + '/blacklist'
|
||||
const fields = {}
|
||||
await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||
await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||
})
|
||||
|
||||
it('Should fail with a non admin user', async function () {
|
||||
const path = basePath + server.video + '/blacklist'
|
||||
const path = basePath + servers[0].video + '/blacklist'
|
||||
const fields = {}
|
||||
await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||
await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid reason', async function () {
|
||||
const path = basePath + server.video.uuid + '/blacklist'
|
||||
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||
const fields = { reason: 'a'.repeat(305) }
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
const path = basePath + server.video.uuid + '/blacklist'
|
||||
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||
const fields = { reason: 'hello' }
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
|
||||
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When getting blacklisted video', function () {
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await getVideo(server.url, server.video.uuid, 401)
|
||||
await getVideo(servers[0].url, servers[0].video.uuid, 401)
|
||||
})
|
||||
|
||||
it('Should fail with another user', async function () {
|
||||
await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403)
|
||||
await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
||||
})
|
||||
|
||||
it('Should succeed with the owner authenticated user', async function () {
|
||||
const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200)
|
||||
const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
|
||||
const video: VideoDetails = res.body
|
||||
|
||||
expect(video.blacklisted).to.be.true
|
||||
})
|
||||
|
||||
it('Should succeed with an admin', async function () {
|
||||
const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200)
|
||||
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
|
||||
const video: VideoDetails = res.body
|
||||
|
||||
expect(video.blacklisted).to.be.true
|
||||
@@ -173,24 +195,24 @@ describe('Test video blacklist API validators', function () {
|
||||
|
||||
describe('When removing a video in blacklist', function () {
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
|
||||
await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
|
||||
})
|
||||
|
||||
it('Should fail with a non admin user', async function () {
|
||||
await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403)
|
||||
await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect id', async function () {
|
||||
await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
|
||||
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
|
||||
})
|
||||
|
||||
it('Should fail with a not blacklisted video', async function () {
|
||||
// The video was not added to the blacklist so it should fail
|
||||
await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
|
||||
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
|
||||
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -198,28 +220,28 @@ describe('Test video blacklist API validators', function () {
|
||||
const basePath = '/api/v1/videos/blacklist/'
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
await getBlacklistedVideosList(server.url, 'fake token', 401)
|
||||
await getBlacklistedVideosList(servers[0].url, 'fake token', 401)
|
||||
})
|
||||
|
||||
it('Should fail with a non admin user', async function () {
|
||||
await getBlacklistedVideosList(server.url, userAccessToken2, 403)
|
||||
await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403)
|
||||
})
|
||||
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, basePath, server.accessToken)
|
||||
await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, basePath, server.accessToken)
|
||||
await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect sort', async function () {
|
||||
await checkBadSortPagination(server.url, basePath, server.accessToken)
|
||||
await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
killallServers([ server ])
|
||||
killallServers(servers)
|
||||
|
||||
// Keep the logs if the test failed
|
||||
if (this['ok']) {
|
||||
|
||||
@@ -13,9 +13,9 @@ import {
|
||||
setAccessTokensToServers,
|
||||
uploadVideo,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
} from '../../../../shared/utils'
|
||||
import { join } from 'path'
|
||||
import { createVideoCaption } from '../../utils/videos/video-captions'
|
||||
import { createVideoCaption } from '../../../../shared/utils/videos/video-captions'
|
||||
|
||||
describe('Test video captions API validator', function () {
|
||||
const path = '/api/v1/videos/'
|
||||
|
||||
@@ -20,8 +20,12 @@ import {
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { User } from '../../../../shared/models/users'
|
||||
import { join } from 'path'
|
||||
|
||||
@@ -118,12 +122,12 @@ describe('Test video channels API validator', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a long description', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
|
||||
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a long support text', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
|
||||
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
@@ -185,12 +189,12 @@ describe('Test video channels API validator', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a long description', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
|
||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should fail with a long support text', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
|
||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
|
||||
@@ -6,9 +6,13 @@ import {
|
||||
createUser,
|
||||
flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
|
||||
uploadVideo, userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { addVideoCommentThread } from '../../utils/videos/video-comments'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
|
||||
@@ -18,9 +18,13 @@ import {
|
||||
setAccessTokensToServers,
|
||||
updateCustomSubConfig,
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/utils/videos/video-imports'
|
||||
|
||||
describe('Test video imports API validator', function () {
|
||||
const path = '/api/v1/videos/imports'
|
||||
@@ -141,7 +145,7 @@ describe('Test video imports API validator', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a long support text', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
127
server/tests/api/check-params/videos-filter.ts
Normal file
127
server/tests/api/check-params/videos-filter.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
/* tslint:disable:no-unused-expression */
|
||||
|
||||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import {
|
||||
createUser,
|
||||
flushTests,
|
||||
killallServers,
|
||||
makeGetRequest,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
userLogin
|
||||
} from '../../../../shared/utils'
|
||||
import { UserRole } from '../../../../shared/models/users'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) {
|
||||
const paths = [
|
||||
'/api/v1/video-channels/root_channel/videos',
|
||||
'/api/v1/accounts/root/videos',
|
||||
'/api/v1/videos',
|
||||
'/api/v1/search/videos'
|
||||
]
|
||||
|
||||
for (const path of paths) {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
token,
|
||||
query: {
|
||||
filter
|
||||
},
|
||||
statusCodeExpected
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
describe('Test videos filters', function () {
|
||||
let server: ServerInfo
|
||||
let userAccessToken: string
|
||||
let moderatorAccessToken: string
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await flushTests()
|
||||
|
||||
server = await runServer(1)
|
||||
|
||||
await setAccessTokensToServers([ server ])
|
||||
|
||||
const user = { username: 'user1', password: 'my super password' }
|
||||
await createUser(server.url, server.accessToken, user.username, user.password)
|
||||
userAccessToken = await userLogin(server, user)
|
||||
|
||||
const moderator = { username: 'moderator', password: 'my super password' }
|
||||
await createUser(
|
||||
server.url,
|
||||
server.accessToken,
|
||||
moderator.username,
|
||||
moderator.password,
|
||||
undefined,
|
||||
undefined,
|
||||
UserRole.MODERATOR
|
||||
)
|
||||
moderatorAccessToken = await userLogin(server, moderator)
|
||||
})
|
||||
|
||||
describe('When setting a video filter', function () {
|
||||
|
||||
it('Should fail with a bad filter', async function () {
|
||||
await testEndpoints(server, server.accessToken, 'bad-filter', 400)
|
||||
})
|
||||
|
||||
it('Should succeed with a good filter', async function () {
|
||||
await testEndpoints(server, server.accessToken,'local', 200)
|
||||
})
|
||||
|
||||
it('Should fail to list all-local with a simple user', async function () {
|
||||
await testEndpoints(server, userAccessToken, 'all-local', 401)
|
||||
})
|
||||
|
||||
it('Should succeed to list all-local with a moderator', async function () {
|
||||
await testEndpoints(server, moderatorAccessToken, 'all-local', 200)
|
||||
})
|
||||
|
||||
it('Should succeed to list all-local with an admin', async function () {
|
||||
await testEndpoints(server, server.accessToken, 'all-local', 200)
|
||||
})
|
||||
|
||||
// Because we cannot authenticate the user on the RSS endpoint
|
||||
it('Should fail on the feeds endpoint with the all-local filter', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path: '/feeds/videos.json',
|
||||
statusCodeExpected: 401,
|
||||
query: {
|
||||
filter: 'all-local'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succed on the feeds endpoint with the local filter', async function () {
|
||||
await makeGetRequest({
|
||||
url: server.url,
|
||||
path: '/feeds/videos.json',
|
||||
statusCodeExpected: 200,
|
||||
query: {
|
||||
filter: 'local'
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
killallServers([ server ])
|
||||
|
||||
// Keep the logs if the test failed
|
||||
if (this['ok']) {
|
||||
await flushTests()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -3,20 +3,25 @@
|
||||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadStartPagination,
|
||||
flushTests,
|
||||
killallServers,
|
||||
makeGetRequest,
|
||||
makePostBodyRequest,
|
||||
makePutBodyRequest,
|
||||
runServer,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
uploadVideo
|
||||
} from '../../utils'
|
||||
} from '../../../../shared/utils'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Test videos history API validator', function () {
|
||||
let path: string
|
||||
let watchingPath: string
|
||||
let myHistoryPath = '/api/v1/users/me/history/videos'
|
||||
let myHistoryRemove = myHistoryPath + '/remove'
|
||||
let server: ServerInfo
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
@@ -33,14 +38,14 @@ describe('Test videos history API validator', function () {
|
||||
const res = await uploadVideo(server.url, server.accessToken, {})
|
||||
const videoUUID = res.body.video.uuid
|
||||
|
||||
path = '/api/v1/videos/' + videoUUID + '/watching'
|
||||
watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
|
||||
})
|
||||
|
||||
describe('When notifying a user is watching a video', function () {
|
||||
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
const fields = { currentTime: 5 }
|
||||
await makePutBodyRequest({ url: server.url, path, fields, statusCodeExpected: 401 })
|
||||
await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect video id', async function () {
|
||||
@@ -58,13 +63,68 @@ describe('Test videos history API validator', function () {
|
||||
|
||||
it('Should fail with a bad current time', async function () {
|
||||
const fields = { currentTime: 'hello' }
|
||||
await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 })
|
||||
await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
const fields = { currentTime: 5 }
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 204 })
|
||||
await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When listing user videos history', function () {
|
||||
it('Should fail with a bad start pagination', async function () {
|
||||
await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with a bad count pagination', async function () {
|
||||
await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
|
||||
})
|
||||
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
|
||||
})
|
||||
|
||||
it('Should succeed with the correct params', async function () {
|
||||
await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When removing user videos history', function () {
|
||||
it('Should fail with an unauthenticated user', async function () {
|
||||
await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 })
|
||||
})
|
||||
|
||||
it('Should fail with a bad beforeDate parameter', async function () {
|
||||
const body = { beforeDate: '15' }
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path: myHistoryRemove,
|
||||
fields: body,
|
||||
statusCodeExpected: 400
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed with a valid beforeDate param', async function () {
|
||||
const body = { beforeDate: new Date().toISOString() }
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path: myHistoryRemove,
|
||||
fields: body,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
|
||||
it('Should succeed without body', async function () {
|
||||
await makePostBodyRequest({
|
||||
url: server.url,
|
||||
token: server.accessToken,
|
||||
path: myHistoryRemove,
|
||||
statusCodeExpected: 204
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -8,9 +8,13 @@ import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enu
|
||||
import {
|
||||
createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
|
||||
makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getAccountsList } from '../../utils/users/accounts'
|
||||
} from '../../../../shared/utils'
|
||||
import {
|
||||
checkBadCountPagination,
|
||||
checkBadSortPagination,
|
||||
checkBadStartPagination
|
||||
} from '../../../../shared/utils/requests/check-api-params'
|
||||
import { getAccountsList } from '../../../../shared/utils/users/accounts'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
@@ -234,7 +238,7 @@ describe('Test videos API validator', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a long support text', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
|
||||
const attaches = baseCorrectAttaches
|
||||
|
||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||
@@ -317,10 +321,15 @@ describe('Test videos API validator', function () {
|
||||
|
||||
it('Should fail without an incorrect input file', async function () {
|
||||
const fields = baseCorrectParams
|
||||
const attaches = {
|
||||
let attaches = {
|
||||
'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
|
||||
}
|
||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||
|
||||
attaches = {
|
||||
'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
|
||||
}
|
||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||
})
|
||||
|
||||
it('Should fail with an incorrect thumbnail file', async function () {
|
||||
@@ -484,7 +493,7 @@ describe('Test videos API validator', function () {
|
||||
})
|
||||
|
||||
it('Should fail with a long support text', async function () {
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
|
||||
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
|
||||
|
||||
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user