diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/videos/video-privacy.ts | 128 |
1 files changed, 98 insertions, 30 deletions
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 40b539106..e630ca84a 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts | |||
@@ -16,14 +16,22 @@ import { userLogin } from '../../../../shared/extra-utils/users/login' | |||
16 | import { createUser } from '../../../../shared/extra-utils/users/users' | 16 | import { createUser } from '../../../../shared/extra-utils/users/users' |
17 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' | 17 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' |
18 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 18 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
19 | import { Video } from '@shared/models' | ||
19 | 20 | ||
20 | const expect = chai.expect | 21 | const expect = chai.expect |
21 | 22 | ||
22 | describe('Test video privacy', function () { | 23 | describe('Test video privacy', function () { |
23 | let servers: ServerInfo[] = [] | 24 | let servers: ServerInfo[] = [] |
25 | let anotherUserToken: string | ||
26 | |||
24 | let privateVideoId: number | 27 | let privateVideoId: number |
25 | let privateVideoUUID: string | 28 | let privateVideoUUID: string |
29 | |||
30 | let internalVideoId: number | ||
31 | let internalVideoUUID: string | ||
32 | |||
26 | let unlistedVideoUUID: string | 33 | let unlistedVideoUUID: string |
34 | |||
27 | let now: number | 35 | let now: number |
28 | 36 | ||
29 | before(async function () { | 37 | before(async function () { |
@@ -39,39 +47,63 @@ describe('Test video privacy', function () { | |||
39 | await doubleFollow(servers[0], servers[1]) | 47 | await doubleFollow(servers[0], servers[1]) |
40 | }) | 48 | }) |
41 | 49 | ||
42 | it('Should upload a private video on server 1', async function () { | 50 | it('Should upload a private and internal videos on server 1', async function () { |
43 | this.timeout(10000) | 51 | this.timeout(10000) |
44 | 52 | ||
45 | const attributes = { | 53 | for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { |
46 | privacy: VideoPrivacy.PRIVATE | 54 | const attributes = { privacy } |
55 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
47 | } | 56 | } |
48 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
49 | 57 | ||
50 | await waitJobs(servers) | 58 | await waitJobs(servers) |
51 | }) | 59 | }) |
52 | 60 | ||
53 | it('Should not have this private video on server 2', async function () { | 61 | it('Should not have these private and internal videos on server 2', async function () { |
54 | const res = await getVideosList(servers[1].url) | 62 | const res = await getVideosList(servers[1].url) |
55 | 63 | ||
56 | expect(res.body.total).to.equal(0) | 64 | expect(res.body.total).to.equal(0) |
57 | expect(res.body.data).to.have.lengthOf(0) | 65 | expect(res.body.data).to.have.lengthOf(0) |
58 | }) | 66 | }) |
59 | 67 | ||
60 | it('Should list my (private) videos', async function () { | 68 | it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { |
61 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1) | 69 | const res = await getVideosList(servers[0].url) |
70 | |||
71 | expect(res.body.total).to.equal(0) | ||
72 | expect(res.body.data).to.have.lengthOf(0) | ||
73 | }) | ||
74 | |||
75 | it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { | ||
76 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | ||
62 | 77 | ||
63 | expect(res.body.total).to.equal(1) | 78 | expect(res.body.total).to.equal(1) |
64 | expect(res.body.data).to.have.lengthOf(1) | 79 | expect(res.body.data).to.have.lengthOf(1) |
65 | 80 | ||
66 | privateVideoId = res.body.data[0].id | 81 | expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) |
67 | privateVideoUUID = res.body.data[0].uuid | 82 | }) |
83 | |||
84 | it('Should list my (private and internal) videos', async function () { | ||
85 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) | ||
86 | |||
87 | expect(res.body.total).to.equal(2) | ||
88 | expect(res.body.data).to.have.lengthOf(2) | ||
89 | |||
90 | const videos: Video[] = res.body.data | ||
91 | |||
92 | const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE) | ||
93 | privateVideoId = privateVideo.id | ||
94 | privateVideoUUID = privateVideo.uuid | ||
95 | |||
96 | const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) | ||
97 | internalVideoId = internalVideo.id | ||
98 | internalVideoUUID = internalVideo.uuid | ||
68 | }) | 99 | }) |
69 | 100 | ||
70 | it('Should not be able to watch this video with non authenticated user', async function () { | 101 | it('Should not be able to watch the private/internal video with non authenticated user', async function () { |
71 | await getVideo(servers[0].url, privateVideoUUID, 401) | 102 | await getVideo(servers[0].url, privateVideoUUID, 401) |
103 | await getVideo(servers[0].url, internalVideoUUID, 401) | ||
72 | }) | 104 | }) |
73 | 105 | ||
74 | it('Should not be able to watch this private video with another user', async function () { | 106 | it('Should not be able to watch the private video with another user', async function () { |
75 | this.timeout(10000) | 107 | this.timeout(10000) |
76 | 108 | ||
77 | const user = { | 109 | const user = { |
@@ -80,12 +112,16 @@ describe('Test video privacy', function () { | |||
80 | } | 112 | } |
81 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) | 113 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) |
82 | 114 | ||
83 | const token = await userLogin(servers[0], user) | 115 | anotherUserToken = await userLogin(servers[0], user) |
84 | await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) | 116 | await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403) |
85 | }) | 117 | }) |
86 | 118 | ||
87 | it('Should be able to watch this video with the correct user', async function () { | 119 | it('Should be able to watch the internal video with another user', async function () { |
88 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID) | 120 | await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200) |
121 | }) | ||
122 | |||
123 | it('Should be able to watch the private video with the correct user', async function () { | ||
124 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200) | ||
89 | }) | 125 | }) |
90 | 126 | ||
91 | it('Should upload an unlisted video on server 2', async function () { | 127 | it('Should upload an unlisted video on server 2', async function () { |
@@ -127,16 +163,27 @@ describe('Test video privacy', function () { | |||
127 | } | 163 | } |
128 | }) | 164 | }) |
129 | 165 | ||
130 | it('Should update the private video to public on server 1', async function () { | 166 | it('Should update the private and internal videos to public on server 1', async function () { |
131 | this.timeout(10000) | 167 | this.timeout(10000) |
132 | 168 | ||
133 | const attribute = { | 169 | now = Date.now() |
134 | name: 'super video public', | 170 | |
135 | privacy: VideoPrivacy.PUBLIC | 171 | { |
172 | const attribute = { | ||
173 | name: 'private video becomes public', | ||
174 | privacy: VideoPrivacy.PUBLIC | ||
175 | } | ||
176 | |||
177 | await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, privateVideoId, attribute) | ||
136 | } | 178 | } |
137 | 179 | ||
138 | now = Date.now() | 180 | { |
139 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) | 181 | const attribute = { |
182 | name: 'internal video becomes public', | ||
183 | privacy: VideoPrivacy.PUBLIC | ||
184 | } | ||
185 | await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, internalVideoId, attribute) | ||
186 | } | ||
140 | 187 | ||
141 | await waitJobs(servers) | 188 | await waitJobs(servers) |
142 | }) | 189 | }) |
@@ -144,18 +191,30 @@ describe('Test video privacy', function () { | |||
144 | it('Should have this new public video listed on server 1 and 2', async function () { | 191 | it('Should have this new public video listed on server 1 and 2', async function () { |
145 | for (const server of servers) { | 192 | for (const server of servers) { |
146 | const res = await getVideosList(server.url) | 193 | const res = await getVideosList(server.url) |
194 | expect(res.body.total).to.equal(2) | ||
195 | expect(res.body.data).to.have.lengthOf(2) | ||
196 | |||
197 | const videos: Video[] = res.body.data | ||
198 | const privateVideo = videos.find(v => v.name === 'private video becomes public') | ||
199 | const internalVideo = videos.find(v => v.name === 'internal video becomes public') | ||
200 | |||
201 | expect(privateVideo).to.not.be.undefined | ||
202 | expect(internalVideo).to.not.be.undefined | ||
203 | |||
204 | expect(new Date(privateVideo.publishedAt).getTime()).to.be.at.least(now) | ||
205 | // We don't change the publish date of internal videos | ||
206 | expect(new Date(internalVideo.publishedAt).getTime()).to.be.below(now) | ||
147 | 207 | ||
148 | expect(res.body.total).to.equal(1) | 208 | expect(privateVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC) |
149 | expect(res.body.data).to.have.lengthOf(1) | 209 | expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC) |
150 | expect(res.body.data[0].name).to.equal('super video public') | ||
151 | expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now) | ||
152 | } | 210 | } |
153 | }) | 211 | }) |
154 | 212 | ||
155 | it('Should set this new video as private', async function () { | 213 | it('Should set these videos as private and internal', async function () { |
156 | this.timeout(10000) | 214 | this.timeout(10000) |
157 | 215 | ||
158 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.PRIVATE }) | 216 | await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) |
217 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) | ||
159 | 218 | ||
160 | await waitJobs(servers) | 219 | await waitJobs(servers) |
161 | 220 | ||
@@ -168,10 +227,19 @@ describe('Test video privacy', function () { | |||
168 | 227 | ||
169 | { | 228 | { |
170 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) | 229 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) |
230 | const videos = res.body.data | ||
231 | |||
232 | expect(res.body.total).to.equal(2) | ||
233 | expect(videos).to.have.lengthOf(2) | ||
234 | |||
235 | const privateVideo = videos.find(v => v.name === 'private video becomes public') | ||
236 | const internalVideo = videos.find(v => v.name === 'internal video becomes public') | ||
237 | |||
238 | expect(privateVideo).to.not.be.undefined | ||
239 | expect(internalVideo).to.not.be.undefined | ||
171 | 240 | ||
172 | expect(res.body.total).to.equal(1) | 241 | expect(privateVideo.privacy.id).to.equal(VideoPrivacy.INTERNAL) |
173 | expect(res.body.data).to.have.lengthOf(1) | 242 | expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PRIVATE) |
174 | expect(res.body.data[0].name).to.equal('super video public') | ||
175 | } | 243 | } |
176 | }) | 244 | }) |
177 | 245 | ||