2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-10-12 09:26:04 -04:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2018-10-12 09:26:04 -04:00
|
|
|
import {
|
2019-04-24 05:54:23 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 04:42:24 -04:00
|
|
|
doubleFollow,
|
2018-10-12 09:26:04 -04:00
|
|
|
makeDeleteRequest,
|
|
|
|
makeGetRequest,
|
|
|
|
makePostBodyRequest,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-07-13 05:05:15 -04:00
|
|
|
setAccessTokensToServers
|
2021-12-17 03:29:23 -05:00
|
|
|
} from '@shared/server-commands'
|
2018-10-12 09:26:04 -04:00
|
|
|
|
|
|
|
describe('Test blocklist API validators', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
|
|
|
let server: PeerTubeServer
|
2018-10-15 07:03:04 -04:00
|
|
|
let userAccessToken: string
|
2018-10-12 09:26:04 -04:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2018-10-12 09:26:04 -04:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
server = servers[0]
|
|
|
|
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.users.create({ username: user.username, password: user.password })
|
2018-10-12 09:26:04 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
userAccessToken = await server.login.getAccessToken(user)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2018-10-12 09:26:04 -04:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
describe('When managing user blocklist', function () {
|
|
|
|
|
|
|
|
describe('When managing user accounts blocklist', function () {
|
2018-10-15 07:03:04 -04:00
|
|
|
const path = '/api/v1/users/me/blocklist/accounts'
|
2018-10-12 09:26:04 -04:00
|
|
|
|
|
|
|
describe('When listing blocked accounts', function () {
|
|
|
|
it('Should fail with an unauthenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown account', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'user2' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-12 11:26:40 -04:00
|
|
|
it('Should fail to block ourselves', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'root' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2018-10-12 11:26:40 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-12 09:26:04 -04:00
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'user1' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When unblocking an account', function () {
|
|
|
|
it('Should fail with an unauthenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown account block', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user2',
|
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1',
|
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-04-14 04:55:34 -04:00
|
|
|
it('Should succeed with an unknown server', async function () {
|
2018-10-12 09:26:04 -04:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { host: 'localhost:9003' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-12 11:26:40 -04:00
|
|
|
it('Should fail with our own server', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + server.port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2018-10-12 11:26:40 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-12 09:26:04 -04:00
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + servers[1].port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When unblocking a server', function () {
|
|
|
|
it('Should fail with an unauthenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 05:54:23 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown server block', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2020-04-14 04:55:34 -04:00
|
|
|
path: path + '/localhost:9004',
|
2018-10-12 09:26:04 -04:00
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 05:54:23 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-10-12 09:26:04 -04:00
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-15 07:03:04 -04:00
|
|
|
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,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: userAccessToken,
|
|
|
|
path,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: userAccessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'user1' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown account', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'user2' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail to block ourselves', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'root' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { accountName: 'user1' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When unblocking an account', function () {
|
|
|
|
it('Should fail with an unauthenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1',
|
|
|
|
token: userAccessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown account block', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user2',
|
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1',
|
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: userAccessToken,
|
|
|
|
path,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + servers[1].port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: userAccessToken,
|
|
|
|
path,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + servers[1].port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-04-14 04:55:34 -04:00
|
|
|
it('Should succeed with an unknown server', async function () {
|
2018-10-15 07:03:04 -04:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
|
|
|
fields: { host: 'localhost:9003' },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with our own server', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + server.port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
token: server.accessToken,
|
|
|
|
path,
|
2019-04-24 05:54:23 -04:00
|
|
|
fields: { host: 'localhost:' + servers[1].port },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When unblocking a server', function () {
|
|
|
|
it('Should fail with an unauthenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 05:54:23 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a user without the appropriate rights', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 05:54:23 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-10-15 07:03:04 -04:00
|
|
|
token: userAccessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown server block', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2020-04-14 04:55:34 -04:00
|
|
|
path: path + '/localhost:9004',
|
2018-10-15 07:03:04 -04:00
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 05:54:23 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-10-15 07:03:04 -04:00
|
|
|
token: server.accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-12-06 10:53:00 -05:00
|
|
|
describe('When getting blocklist status', function () {
|
|
|
|
const path = '/api/v1/blocklist/status'
|
|
|
|
|
|
|
|
it('Should fail with a bad token', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: 'false',
|
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad accounts field', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
accounts: 1
|
|
|
|
},
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
accounts: [ 1 ]
|
|
|
|
},
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad hosts field', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
hosts: 1
|
|
|
|
},
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
hosts: [ 1 ]
|
|
|
|
},
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {},
|
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
hosts: [ 'example.com' ],
|
|
|
|
accounts: [ 'john@example.com' ]
|
|
|
|
},
|
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 05:54:23 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-10-12 09:26:04 -04:00
|
|
|
})
|
|
|
|
})
|