2017-11-17 09:20:42 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
|
|
|
createUser,
|
|
|
|
flushAndRunServer,
|
2019-11-28 05:37:32 -05:00
|
|
|
makeDeleteRequest, makeGetRequest,
|
2019-04-24 09:10:37 -04:00
|
|
|
makePostBodyRequest,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2017-12-28 08:29:57 -05:00
|
|
|
userLogin
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-10-29 12:48:31 -04:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
2017-11-17 09:20:42 -05:00
|
|
|
|
|
|
|
describe('Test server follows API validators', function () {
|
|
|
|
let server: ServerInfo
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
2018-01-18 12:10:45 -05:00
|
|
|
this.timeout(30000)
|
2017-11-17 09:20:42 -05:00
|
|
|
|
2019-04-24 04:53:40 -04:00
|
|
|
server = await flushAndRunServer(1)
|
2017-11-17 09:20:42 -05:00
|
|
|
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When managing following', function () {
|
|
|
|
let userAccessToken = null
|
|
|
|
|
|
|
|
before(async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
const user = {
|
2017-11-17 09:20:42 -05:00
|
|
|
username: 'user1',
|
|
|
|
password: 'password'
|
|
|
|
}
|
|
|
|
|
2019-04-15 04:49:46 -04:00
|
|
|
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
|
2017-12-28 08:29:57 -05:00
|
|
|
userAccessToken = await userLogin(server, user)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When adding follows', function () {
|
|
|
|
const path = '/api/v1/server/following'
|
|
|
|
|
|
|
|
it('Should fail without hosts', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if hosts is not an array', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { hosts: 'localhost:9002' },
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the array is not composed by hosts', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the array is composed with http schemes', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if hosts are not unique', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
fields: { hosts: [ 'localhost:9002' ] },
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
fields: { hosts: [ 'localhost:9002' ] },
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing followings', function () {
|
|
|
|
const path = '/api/v1/server/following'
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadStartPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadCountPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadSortPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
2019-11-28 05:37:32 -05:00
|
|
|
|
|
|
|
it('Should fail with an incorrect state', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
state: 'blabla'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-11-29 04:55:17 -05:00
|
|
|
it('Should fail with an incorrect actor type', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
actorType: 'blabla'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-11-28 05:37:32 -05:00
|
|
|
it('Should fail succeed with the correct params', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: 200,
|
|
|
|
query: {
|
2019-11-29 04:55:17 -05:00
|
|
|
state: 'accepted',
|
|
|
|
actorType: 'Application'
|
2019-11-28 05:37:32 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing followers', function () {
|
|
|
|
const path = '/api/v1/server/followers'
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadStartPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadCountPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await checkBadSortPagination(server.url, path)
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
2019-11-28 05:37:32 -05:00
|
|
|
|
2019-11-29 04:55:17 -05:00
|
|
|
it('Should fail with an incorrect actor type', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
|
|
|
actorType: 'blabla'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-11-28 05:37:32 -05:00
|
|
|
it('Should fail with an incorrect state', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
query: {
|
2019-11-29 04:55:17 -05:00
|
|
|
state: 'blabla',
|
|
|
|
actorType: 'Application'
|
2019-11-28 05:37:32 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail succeed with the correct params', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: 200,
|
|
|
|
query: {
|
|
|
|
state: 'accepted'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
|
2019-04-08 08:04:57 -04:00
|
|
|
describe('When removing a follower', function () {
|
|
|
|
const path = '/api/v1/server/followers'
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002',
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002',
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid follower', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown follower', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9003',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-08 09:18:04 -04:00
|
|
|
describe('When accepting a follower', function () {
|
|
|
|
const path = '/api/v1/server/followers'
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002/accept',
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002/accept',
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid follower', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto/accept',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown follower', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9003/accept',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When rejecting a follower', function () {
|
|
|
|
const path = '/api/v1/server/followers'
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002/reject',
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9002/reject',
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid follower', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto/reject',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown follower', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/toto@localhost:9003/reject',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-17 09:20:42 -05:00
|
|
|
describe('When removing following', function () {
|
2017-11-21 07:43:29 -05:00
|
|
|
const path = '/api/v1/server/following'
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/localhost:9002',
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
2017-11-21 07:43:29 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
2017-12-28 08:29:57 -05:00
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/localhost:9002',
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if we do not follow this server', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/example.com',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2017-11-17 09:20:42 -05:00
|
|
|
})
|
|
|
|
})
|