diff options
Diffstat (limited to 'server/tests/api/video-privacy.ts')
-rw-r--r-- | server/tests/api/video-privacy.ts | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/server/tests/api/video-privacy.ts b/server/tests/api/video-privacy.ts new file mode 100644 index 000000000..beac1613e --- /dev/null +++ b/server/tests/api/video-privacy.ts | |||
@@ -0,0 +1,158 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | makeFriends, | ||
12 | getVideosList, | ||
13 | wait, | ||
14 | setAccessTokensToServers, | ||
15 | flushAndRunMultipleServers, | ||
16 | killallServers | ||
17 | } from '../utils' | ||
18 | import { VideoPrivacy } from '../../../shared/models/videos/video-privacy.enum' | ||
19 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../utils/videos' | ||
20 | import { createUser } from '../utils/users' | ||
21 | import { getUserAccessToken } from '../utils/login' | ||
22 | |||
23 | describe('Test video privacy', function () { | ||
24 | let servers: ServerInfo[] = [] | ||
25 | let privateVideoId | ||
26 | let privateVideoUUID | ||
27 | let unlistedVideoUUID | ||
28 | |||
29 | before(async function () { | ||
30 | this.timeout(120000) | ||
31 | |||
32 | // Run servers | ||
33 | servers = await flushAndRunMultipleServers(2) | ||
34 | |||
35 | // Get the access tokens | ||
36 | await setAccessTokensToServers(servers) | ||
37 | |||
38 | // Pod 1 makes friend with pod 2 | ||
39 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
40 | }) | ||
41 | |||
42 | it('Should upload a private video on pod 1', async function () { | ||
43 | this.timeout(15000) | ||
44 | |||
45 | const attributes = { | ||
46 | privacy: VideoPrivacy.PRIVATE | ||
47 | } | ||
48 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
49 | |||
50 | await wait(11000) | ||
51 | }) | ||
52 | |||
53 | it('Should not have this private video on pod 2', async function () { | ||
54 | const res = await getVideosList(servers[1].url) | ||
55 | |||
56 | expect(res.body.total).to.equal(0) | ||
57 | expect(res.body.data).to.have.lengthOf(0) | ||
58 | }) | ||
59 | |||
60 | it('Should list my (private) videos', async function () { | ||
61 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1) | ||
62 | |||
63 | expect(res.body.total).to.equal(1) | ||
64 | expect(res.body.data).to.have.lengthOf(1) | ||
65 | |||
66 | privateVideoId = res.body.data[0].id | ||
67 | privateVideoUUID = res.body.data[0].uuid | ||
68 | }) | ||
69 | |||
70 | it('Should not be able to watch this video with non authenticated user', async function () { | ||
71 | await getVideo(servers[0].url, privateVideoUUID, 401) | ||
72 | }) | ||
73 | |||
74 | it('Should not be able to watch this private video with another user', async function () { | ||
75 | const user = { | ||
76 | username: 'hello', | ||
77 | password: 'super password' | ||
78 | } | ||
79 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
80 | |||
81 | const token = await getUserAccessToken(servers[0], user) | ||
82 | await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) | ||
83 | }) | ||
84 | |||
85 | it('Should be able to watch this video with the correct user', async function () { | ||
86 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID) | ||
87 | }) | ||
88 | |||
89 | it('Should upload a unlisted video on pod 2', async function () { | ||
90 | this.timeout(30000) | ||
91 | |||
92 | const attributes = { | ||
93 | name: 'unlisted video', | ||
94 | privacy: VideoPrivacy.UNLISTED | ||
95 | } | ||
96 | await uploadVideo(servers[1].url, servers[1].accessToken, attributes) | ||
97 | |||
98 | await wait(22000) | ||
99 | }) | ||
100 | |||
101 | it('Should not have this unlisted video listed on pod 1 and 2', async function () { | ||
102 | for (const server of servers) { | ||
103 | const res = await getVideosList(server.url) | ||
104 | |||
105 | expect(res.body.total).to.equal(0) | ||
106 | expect(res.body.data).to.have.lengthOf(0) | ||
107 | } | ||
108 | }) | ||
109 | |||
110 | it('Should list my (unlisted) videos', async function () { | ||
111 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) | ||
112 | |||
113 | expect(res.body.total).to.equal(1) | ||
114 | expect(res.body.data).to.have.lengthOf(1) | ||
115 | |||
116 | unlistedVideoUUID = res.body.data[0].uuid | ||
117 | }) | ||
118 | |||
119 | it('Should be able to get this unlisted video', async function () { | ||
120 | for (const server of servers) { | ||
121 | const res = await getVideo(server.url, unlistedVideoUUID) | ||
122 | |||
123 | expect(res.body.name).to.equal('unlisted video') | ||
124 | } | ||
125 | }) | ||
126 | |||
127 | it('Should update the private video to public on pod 1', async function () { | ||
128 | this.timeout(15000) | ||
129 | |||
130 | const attribute = { | ||
131 | name: 'super video public', | ||
132 | privacy: VideoPrivacy.PUBLIC | ||
133 | } | ||
134 | |||
135 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) | ||
136 | |||
137 | await wait(11000) | ||
138 | }) | ||
139 | |||
140 | it('Should not have this new unlisted video listed on pod 1 and 2', async function () { | ||
141 | for (const server of servers) { | ||
142 | const res = await getVideosList(server.url) | ||
143 | |||
144 | expect(res.body.total).to.equal(1) | ||
145 | expect(res.body.data).to.have.lengthOf(1) | ||
146 | expect(res.body.data[0].name).to.equal('super video public') | ||
147 | } | ||
148 | }) | ||
149 | |||
150 | after(async function () { | ||
151 | killallServers(servers) | ||
152 | |||
153 | // Keep the logs if the test failed | ||
154 | if (this['ok']) { | ||
155 | await flushTests() | ||
156 | } | ||
157 | }) | ||
158 | }) | ||