diff options
Diffstat (limited to 'server/tests/api/videos/video-privacy.ts')
-rw-r--r-- | server/tests/api/videos/video-privacy.ts | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts new file mode 100644 index 000000000..de709f8f1 --- /dev/null +++ b/server/tests/api/videos/video-privacy.ts | |||
@@ -0,0 +1,159 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
6 | import { | ||
7 | flushAndRunMultipleServers, | ||
8 | flushTests, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers, | ||
13 | uploadVideo, | ||
14 | wait | ||
15 | } from '../../utils/index' | ||
16 | import { doubleFollow } from '../../utils/server/follows' | ||
17 | import { getUserAccessToken } from '../../utils/users/login' | ||
18 | import { createUser } from '../../utils/users/users' | ||
19 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos' | ||
20 | |||
21 | const expect = chai.expect | ||
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(50000) | ||
31 | |||
32 | // Run servers | ||
33 | servers = await flushAndRunMultipleServers(2) | ||
34 | |||
35 | // Get the access tokens | ||
36 | await setAccessTokensToServers(servers) | ||
37 | |||
38 | // Server 1 and server 2 follow each other | ||
39 | await doubleFollow(servers[0], servers[1]) | ||
40 | }) | ||
41 | |||
42 | it('Should upload a private video on server 1', async function () { | ||
43 | this.timeout(10000) | ||
44 | |||
45 | const attributes = { | ||
46 | privacy: VideoPrivacy.PRIVATE | ||
47 | } | ||
48 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
49 | |||
50 | await wait(5000) | ||
51 | }) | ||
52 | |||
53 | it('Should not have this private video on server 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 an unlisted video on server 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 | // Server 2 has transcoding enabled | ||
99 | await wait(10000) | ||
100 | }) | ||
101 | |||
102 | it('Should not have this unlisted video listed on server 1 and 2', async function () { | ||
103 | for (const server of servers) { | ||
104 | const res = await getVideosList(server.url) | ||
105 | |||
106 | expect(res.body.total).to.equal(0) | ||
107 | expect(res.body.data).to.have.lengthOf(0) | ||
108 | } | ||
109 | }) | ||
110 | |||
111 | it('Should list my (unlisted) videos', async function () { | ||
112 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) | ||
113 | |||
114 | expect(res.body.total).to.equal(1) | ||
115 | expect(res.body.data).to.have.lengthOf(1) | ||
116 | |||
117 | unlistedVideoUUID = res.body.data[0].uuid | ||
118 | }) | ||
119 | |||
120 | it('Should be able to get this unlisted video', async function () { | ||
121 | for (const server of servers) { | ||
122 | const res = await getVideo(server.url, unlistedVideoUUID) | ||
123 | |||
124 | expect(res.body.name).to.equal('unlisted video') | ||
125 | } | ||
126 | }) | ||
127 | |||
128 | it('Should update the private video to public on server 1', async function () { | ||
129 | this.timeout(10000) | ||
130 | |||
131 | const attribute = { | ||
132 | name: 'super video public', | ||
133 | privacy: VideoPrivacy.PUBLIC | ||
134 | } | ||
135 | |||
136 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) | ||
137 | |||
138 | await wait(5000) | ||
139 | }) | ||
140 | |||
141 | it('Should have this new public video listed on server 1 and 2', async function () { | ||
142 | for (const server of servers) { | ||
143 | const res = await getVideosList(server.url) | ||
144 | |||
145 | expect(res.body.total).to.equal(1) | ||
146 | expect(res.body.data).to.have.lengthOf(1) | ||
147 | expect(res.body.data[0].name).to.equal('super video public') | ||
148 | } | ||
149 | }) | ||
150 | |||
151 | after(async function () { | ||
152 | killallServers(servers) | ||
153 | |||
154 | // Keep the logs if the test failed | ||
155 | if (this['ok']) { | ||
156 | await flushTests() | ||
157 | } | ||
158 | }) | ||
159 | }) | ||