1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* tslint:disable:no-unused-expression */
import 'mocha'
import {
createUser,
doubleFollow,
flushAndRunMultipleServers,
flushTests,
killallServers,
makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
userLogin
} from '../../../../shared/utils'
describe('Test server redundancy API validators', function () {
let servers: ServerInfo[]
let userAccessToken = null
// ---------------------------------------------------------------
before(async function () {
this.timeout(30000)
await flushTests()
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
const user = {
username: 'user1',
password: 'password'
}
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(servers[0], user)
})
describe('When updating redundancy', function () {
const path = '/api/v1/server/redundancy'
it('Should fail with an invalid token', async function () {
await makePutBodyRequest({
url: servers[0].url,
path: path + '/localhost:9002',
fields: { redundancyAllowed: true },
token: 'fake_token',
statusCodeExpected: 401
})
})
it('Should fail if the user is not an administrator', async function () {
await makePutBodyRequest({
url: servers[0].url,
path: path + '/localhost:9002',
fields: { redundancyAllowed: true },
token: userAccessToken,
statusCodeExpected: 403
})
})
it('Should fail if we do not follow this server', async function () {
await makePutBodyRequest({
url: servers[0].url,
path: path + '/example.com',
fields: { redundancyAllowed: true },
token: servers[0].accessToken,
statusCodeExpected: 404
})
})
it('Should fail without de redundancyAllowed param', async function () {
await makePutBodyRequest({
url: servers[0].url,
path: path + '/localhost:9002',
fields: { blabla: true },
token: servers[0].accessToken,
statusCodeExpected: 400
})
})
it('Should succeed with the correct parameters', async function () {
await makePutBodyRequest({
url: servers[0].url,
path: path + '/localhost:9002',
fields: { redundancyAllowed: true },
token: servers[0].accessToken,
statusCodeExpected: 204
})
})
})
after(async function () {
killallServers(servers)
// Keep the logs if the test failed
if (this['ok']) {
await flushTests()
}
})
})
|