diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-08 21:16:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 21:16:10 +0100 |
commit | f2eb23cd87cf32b8fe545178143b5f49e06a58da (patch) | |
tree | af7d59945af70e28fd85047e2c688c59a908f548 /server/tests/api/videos | |
parent | c977fd3ec931c059111ddb2b8d6ddbb20b6b99a1 (diff) | |
download | PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.gz PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.zst PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.zip |
emit more specific status codes on video upload (#3423)
- reduce http status codes list to potentially useful codes
- convert more codes to typed ones
- factorize html generator for error responses
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 5 | ||||
-rw-r--r-- | server/tests/api/videos/video-change-ownership.ts | 14 | ||||
-rw-r--r-- | server/tests/api/videos/video-hls.ts | 9 | ||||
-rw-r--r-- | server/tests/api/videos/video-playlists.ts | 13 | ||||
-rw-r--r-- | server/tests/api/videos/video-privacy.ts | 13 | ||||
-rw-r--r-- | server/tests/api/videos/videos-history.ts | 3 |
6 files changed, 35 insertions, 22 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index fdd5e33f3..f754df04e 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -41,6 +41,7 @@ import { | |||
41 | findCommentId | 41 | findCommentId |
42 | } from '../../../../shared/extra-utils/videos/video-comments' | 42 | } from '../../../../shared/extra-utils/videos/video-comments' |
43 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 43 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
44 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
44 | 45 | ||
45 | const expect = chai.expect | 46 | const expect = chai.expect |
46 | 47 | ||
@@ -999,7 +1000,7 @@ describe('Test multiple servers', function () { | |||
999 | expect(res.body.downloadEnabled).to.be.false | 1000 | expect(res.body.downloadEnabled).to.be.false |
1000 | 1001 | ||
1001 | const text = 'my super forbidden comment' | 1002 | const text = 'my super forbidden comment' |
1002 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409) | 1003 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) |
1003 | } | 1004 | } |
1004 | }) | 1005 | }) |
1005 | }) | 1006 | }) |
@@ -1021,7 +1022,7 @@ describe('Test multiple servers', function () { | |||
1021 | const filePath = join(__dirname, '..', '..', 'fixtures', 'video_short.webm') | 1022 | const filePath = join(__dirname, '..', '..', 'fixtures', 'video_short.webm') |
1022 | 1023 | ||
1023 | await req.attach('videofile', filePath) | 1024 | await req.attach('videofile', filePath) |
1024 | .expect(200) | 1025 | .expect(HttpStatusCode.OK_200) |
1025 | 1026 | ||
1026 | await waitJobs(servers) | 1027 | await waitJobs(servers) |
1027 | 1028 | ||
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index dee6575b9..fad4c8b1f 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts | |||
@@ -23,6 +23,7 @@ import { | |||
23 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 23 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
24 | import { User } from '../../../../shared/models/users' | 24 | import { User } from '../../../../shared/models/users' |
25 | import { VideoDetails } from '../../../../shared/models/videos' | 25 | import { VideoDetails } from '../../../../shared/models/videos' |
26 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
26 | 27 | ||
27 | const expect = chai.expect | 28 | const expect = chai.expect |
28 | 29 | ||
@@ -140,7 +141,7 @@ describe('Test video change ownership - nominal', function () { | |||
140 | it('Should not be possible to refuse the change of ownership from first user', async function () { | 141 | it('Should not be possible to refuse the change of ownership from first user', async function () { |
141 | this.timeout(10000) | 142 | this.timeout(10000) |
142 | 143 | ||
143 | await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, 403) | 144 | await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) |
144 | }) | 145 | }) |
145 | 146 | ||
146 | it('Should be possible to refuse the change of ownership from second user', async function () { | 147 | it('Should be possible to refuse the change of ownership from second user', async function () { |
@@ -177,7 +178,7 @@ describe('Test video change ownership - nominal', function () { | |||
177 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) | 178 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) |
178 | const secondUserInformation: User = secondUserInformationResponse.body | 179 | const secondUserInformation: User = secondUserInformationResponse.body |
179 | const channelId = secondUserInformation.videoChannels[0].id | 180 | const channelId = secondUserInformation.videoChannels[0].id |
180 | await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) | 181 | await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, HttpStatusCode.FORBIDDEN_403) |
181 | }) | 182 | }) |
182 | 183 | ||
183 | it('Should be possible to accept the change of ownership from second user', async function () { | 184 | it('Should be possible to accept the change of ownership from second user', async function () { |
@@ -294,7 +295,14 @@ describe('Test video change ownership - quota too small', function () { | |||
294 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | 295 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) |
295 | const secondUserInformation: User = secondUserInformationResponse.body | 296 | const secondUserInformation: User = secondUserInformationResponse.body |
296 | const channelId = secondUserInformation.videoChannels[0].id | 297 | const channelId = secondUserInformation.videoChannels[0].id |
297 | await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) | 298 | |
299 | await acceptChangeOwnership( | ||
300 | server.url, | ||
301 | secondUserAccessToken, | ||
302 | lastRequestChangeOwnershipId, | ||
303 | channelId, | ||
304 | HttpStatusCode.PAYLOAD_TOO_LARGE_413 | ||
305 | ) | ||
298 | }) | 306 | }) |
299 | 307 | ||
300 | after(async function () { | 308 | after(async function () { |
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 3a65cc1d2..f3dbbb114 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts | |||
@@ -26,6 +26,7 @@ import { | |||
26 | import { VideoDetails } from '../../../../shared/models/videos' | 26 | import { VideoDetails } from '../../../../shared/models/videos' |
27 | import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' | 27 | import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' |
28 | import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' | 28 | import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' |
29 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
29 | 30 | ||
30 | const expect = chai.expect | 31 | const expect = chai.expect |
31 | 32 | ||
@@ -57,8 +58,8 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn | |||
57 | ) | 58 | ) |
58 | expect(file.resolution.label).to.equal(resolution + 'p') | 59 | expect(file.resolution.label).to.equal(resolution + 'p') |
59 | 60 | ||
60 | await makeRawRequest(file.torrentUrl, 200) | 61 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
61 | await makeRawRequest(file.fileUrl, 200) | 62 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) |
62 | 63 | ||
63 | const torrent = await webtorrentAdd(file.magnetUri, true) | 64 | const torrent = await webtorrentAdd(file.magnetUri, true) |
64 | expect(torrent.files).to.be.an('array') | 65 | expect(torrent.files).to.be.an('array') |
@@ -144,8 +145,8 @@ describe('Test HLS videos', function () { | |||
144 | await waitJobs(servers) | 145 | await waitJobs(servers) |
145 | 146 | ||
146 | for (const server of servers) { | 147 | for (const server of servers) { |
147 | await getVideo(server.url, videoUUID, 404) | 148 | await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) |
148 | await getVideo(server.url, videoAudioUUID, 404) | 149 | await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) |
149 | } | 150 | } |
150 | }) | 151 | }) |
151 | 152 | ||
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 7d1215990..0a96ea9a0 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts | |||
@@ -61,6 +61,7 @@ import { | |||
61 | removeServerFromAccountBlocklist, | 61 | removeServerFromAccountBlocklist, |
62 | removeServerFromServerBlocklist | 62 | removeServerFromServerBlocklist |
63 | } from '../../../../shared/extra-utils/users/blocklist' | 63 | } from '../../../../shared/extra-utils/users/blocklist' |
64 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
64 | 65 | ||
65 | const expect = chai.expect | 66 | const expect = chai.expect |
66 | 67 | ||
@@ -1091,7 +1092,7 @@ describe('Test video playlists', function () { | |||
1091 | await waitJobs(servers) | 1092 | await waitJobs(servers) |
1092 | 1093 | ||
1093 | for (const server of servers) { | 1094 | for (const server of servers) { |
1094 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 200) | 1095 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.OK_200) |
1095 | } | 1096 | } |
1096 | 1097 | ||
1097 | const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } | 1098 | const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } |
@@ -1100,11 +1101,11 @@ describe('Test video playlists', function () { | |||
1100 | await waitJobs(servers) | 1101 | await waitJobs(servers) |
1101 | 1102 | ||
1102 | for (const server of [ servers[1], servers[2] ]) { | 1103 | for (const server of [ servers[1], servers[2] ]) { |
1103 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 404) | 1104 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.NOT_FOUND_404) |
1104 | } | 1105 | } |
1105 | await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, 401) | 1106 | await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, HttpStatusCode.UNAUTHORIZED_401) |
1106 | 1107 | ||
1107 | await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, 200) | 1108 | await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, HttpStatusCode.OK_200) |
1108 | }) | 1109 | }) |
1109 | }) | 1110 | }) |
1110 | 1111 | ||
@@ -1118,7 +1119,7 @@ describe('Test video playlists', function () { | |||
1118 | await waitJobs(servers) | 1119 | await waitJobs(servers) |
1119 | 1120 | ||
1120 | for (const server of servers) { | 1121 | for (const server of servers) { |
1121 | await getVideoPlaylist(server.url, playlistServer1UUID, 404) | 1122 | await getVideoPlaylist(server.url, playlistServer1UUID, HttpStatusCode.NOT_FOUND_404) |
1122 | } | 1123 | } |
1123 | }) | 1124 | }) |
1124 | 1125 | ||
@@ -1178,7 +1179,7 @@ describe('Test video playlists', function () { | |||
1178 | expect(res3.body.displayName).to.equal('channel playlist') | 1179 | expect(res3.body.displayName).to.equal('channel playlist') |
1179 | expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) | 1180 | expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) |
1180 | 1181 | ||
1181 | await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404) | 1182 | await getVideoPlaylist(servers[1].url, videoPlaylistUUID, HttpStatusCode.NOT_FOUND_404) |
1182 | }) | 1183 | }) |
1183 | 1184 | ||
1184 | it('Should delete an account and delete its playlists', async function () { | 1185 | it('Should delete an account and delete its playlists', async function () { |
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 38e93bbe6..f25d75af4 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts | |||
@@ -18,6 +18,7 @@ import { createUser } from '../../../../shared/extra-utils/users/users' | |||
18 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' | 18 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
20 | import { Video } from '@shared/models' | 20 | import { Video } from '@shared/models' |
21 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
21 | 22 | ||
22 | const expect = chai.expect | 23 | const expect = chai.expect |
23 | 24 | ||
@@ -110,8 +111,8 @@ describe('Test video privacy', function () { | |||
110 | }) | 111 | }) |
111 | 112 | ||
112 | it('Should not be able to watch the private/internal video with non authenticated user', async function () { | 113 | it('Should not be able to watch the private/internal video with non authenticated user', async function () { |
113 | await getVideo(servers[0].url, privateVideoUUID, 401) | 114 | await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401) |
114 | await getVideo(servers[0].url, internalVideoUUID, 401) | 115 | await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) |
115 | }) | 116 | }) |
116 | 117 | ||
117 | it('Should not be able to watch the private video with another user', async function () { | 118 | it('Should not be able to watch the private video with another user', async function () { |
@@ -124,15 +125,15 @@ describe('Test video privacy', function () { | |||
124 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | 125 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
125 | 126 | ||
126 | anotherUserToken = await userLogin(servers[0], user) | 127 | anotherUserToken = await userLogin(servers[0], user) |
127 | await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403) | 128 | await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) |
128 | }) | 129 | }) |
129 | 130 | ||
130 | it('Should be able to watch the internal video with another user', async function () { | 131 | it('Should be able to watch the internal video with another user', async function () { |
131 | await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200) | 132 | await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200) |
132 | }) | 133 | }) |
133 | 134 | ||
134 | it('Should be able to watch the private video with the correct user', async function () { | 135 | it('Should be able to watch the private video with the correct user', async function () { |
135 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200) | 136 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200) |
136 | }) | 137 | }) |
137 | 138 | ||
138 | it('Should upload an unlisted video on server 2', async function () { | 139 | it('Should upload an unlisted video on server 2', async function () { |
@@ -202,7 +203,7 @@ describe('Test video privacy', function () { | |||
202 | }) | 203 | }) |
203 | 204 | ||
204 | it('Should not be able to get non-federated unlisted video from federated server', async function () { | 205 | it('Should not be able to get non-federated unlisted video from federated server', async function () { |
205 | await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, 404) | 206 | await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404) |
206 | }) | 207 | }) |
207 | 208 | ||
208 | it('Should update the private and internal videos to public on server 1', async function () { | 209 | it('Should update the private and internal videos to public on server 1', async function () { |
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 6f90e9a57..661d603cb 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts | |||
@@ -20,6 +20,7 @@ import { | |||
20 | } from '../../../../shared/extra-utils' | 20 | } from '../../../../shared/extra-utils' |
21 | import { Video, VideoDetails } from '../../../../shared/models/videos' | 21 | import { Video, VideoDetails } from '../../../../shared/models/videos' |
22 | import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' | 22 | import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' |
23 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
23 | 24 | ||
24 | const expect = chai.expect | 25 | const expect = chai.expect |
25 | 26 | ||
@@ -171,7 +172,7 @@ describe('Test videos history', function () { | |||
171 | videosHistoryEnabled: false | 172 | videosHistoryEnabled: false |
172 | }) | 173 | }) |
173 | 174 | ||
174 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8, 409) | 175 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) |
175 | }) | 176 | }) |
176 | 177 | ||
177 | it('Should re-enable videos history', async function () { | 178 | it('Should re-enable videos history', async function () { |