]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | cleanupTests, | |
6 | createUser, | |
7 | flushAndRunServer, | |
8 | makeGetRequest, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | setDefaultVideoChannel, | |
12 | userLogin | |
13 | } from '../../../../shared/extra-utils' | |
14 | import { UserRole } from '../../../../shared/models/users' | |
15 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
16 | ||
17 | async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { | |
18 | const paths = [ | |
19 | '/api/v1/video-channels/root_channel/videos', | |
20 | '/api/v1/accounts/root/videos', | |
21 | '/api/v1/videos', | |
22 | '/api/v1/search/videos' | |
23 | ] | |
24 | ||
25 | for (const path of paths) { | |
26 | await makeGetRequest({ | |
27 | url: server.url, | |
28 | path, | |
29 | token, | |
30 | query: { | |
31 | filter | |
32 | }, | |
33 | statusCodeExpected | |
34 | }) | |
35 | } | |
36 | } | |
37 | ||
38 | describe('Test video filters validators', function () { | |
39 | let server: ServerInfo | |
40 | let userAccessToken: string | |
41 | let moderatorAccessToken: string | |
42 | ||
43 | // --------------------------------------------------------------- | |
44 | ||
45 | before(async function () { | |
46 | this.timeout(30000) | |
47 | ||
48 | server = await flushAndRunServer(1) | |
49 | ||
50 | await setAccessTokensToServers([ server ]) | |
51 | await setDefaultVideoChannel([ server ]) | |
52 | ||
53 | const user = { username: 'user1', password: 'my super password' } | |
54 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
55 | userAccessToken = await userLogin(server, user) | |
56 | ||
57 | const moderator = { username: 'moderator', password: 'my super password' } | |
58 | await createUser( | |
59 | { | |
60 | url: server.url, | |
61 | accessToken: server.accessToken, | |
62 | username: moderator.username, | |
63 | password: moderator.password, | |
64 | videoQuota: undefined, | |
65 | videoQuotaDaily: undefined, | |
66 | role: UserRole.MODERATOR | |
67 | } | |
68 | ) | |
69 | moderatorAccessToken = await userLogin(server, moderator) | |
70 | }) | |
71 | ||
72 | describe('When setting a video filter', function () { | |
73 | ||
74 | it('Should fail with a bad filter', async function () { | |
75 | await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) | |
76 | }) | |
77 | ||
78 | it('Should succeed with a good filter', async function () { | |
79 | await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200) | |
80 | }) | |
81 | ||
82 | it('Should fail to list all-local/all with a simple user', async function () { | |
83 | await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) | |
84 | await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) | |
85 | }) | |
86 | ||
87 | it('Should succeed to list all-local/all with a moderator', async function () { | |
88 | await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) | |
89 | await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200) | |
90 | }) | |
91 | ||
92 | it('Should succeed to list all-local/all with an admin', async function () { | |
93 | await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200) | |
94 | await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200) | |
95 | }) | |
96 | ||
97 | // Because we cannot authenticate the user on the RSS endpoint | |
98 | it('Should fail on the feeds endpoint with the all-local/all filter', async function () { | |
99 | for (const filter of [ 'all', 'all-local' ]) { | |
100 | await makeGetRequest({ | |
101 | url: server.url, | |
102 | path: '/feeds/videos.json', | |
103 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, | |
104 | query: { | |
105 | filter | |
106 | } | |
107 | }) | |
108 | } | |
109 | }) | |
110 | ||
111 | it('Should succeed on the feeds endpoint with the local filter', async function () { | |
112 | await makeGetRequest({ | |
113 | url: server.url, | |
114 | path: '/feeds/videos.json', | |
115 | statusCodeExpected: HttpStatusCode.OK_200, | |
116 | query: { | |
117 | filter: 'local' | |
118 | } | |
119 | }) | |
120 | }) | |
121 | }) | |
122 | ||
123 | after(async function () { | |
124 | await cleanupTests([ server ]) | |
125 | }) | |
126 | }) |