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