From f2eb23cd87cf32b8fe545178143b5f49e06a58da Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 8 Dec 2020 21:16:10 +0100 Subject: 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 --- server/tests/api/live/live-save-replay.ts | 33 ++++++++++++++++--------------- server/tests/api/live/live.ts | 19 +++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'server/tests/api/live') diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 3ffa0c093..e300ec345 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -25,6 +25,7 @@ import { waitJobs, waitUntilLiveStarts } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -118,7 +119,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) }) @@ -130,7 +131,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) @@ -142,7 +143,7 @@ describe('Save replay setting', function () { await waitJobs(servers) // Live still exist, but cannot be played anymore - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) // No resolutions saved since we did not save replay @@ -158,7 +159,7 @@ describe('Save replay setting', function () { await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), @@ -169,8 +170,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, 401) - await getVideo(servers[1].url, liveVideoUUID, 404) + await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) @@ -184,7 +185,7 @@ describe('Save replay setting', function () { await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ testFfmpegStreamError(ffmpegCommand, true), @@ -193,7 +194,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 404) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) }) @@ -207,7 +208,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) }) @@ -219,7 +220,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) @@ -231,7 +232,7 @@ describe('Save replay setting', function () { await waitJobs(servers) // Live has been transcoded - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) @@ -261,7 +262,7 @@ describe('Save replay setting', function () { await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), @@ -272,8 +273,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, 401) - await getVideo(servers[1].url, liveVideoUUID, 404) + await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) }) @@ -287,7 +288,7 @@ describe('Save replay setting', function () { await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), @@ -296,7 +297,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 404) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index d784650b5..fdfc6105f 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -44,6 +44,7 @@ import { waitUntilLiveStarts, waitUntilLog } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -164,8 +165,8 @@ describe('Test live', function () { expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) expect(video.nsfw).to.be.true - await makeRawRequest(server.url + video.thumbnailPath, 200) - await makeRawRequest(server.url + video.previewPath, 200) + await makeRawRequest(server.url + video.thumbnailPath, HttpStatusCode.OK_200) + await makeRawRequest(server.url + video.previewPath, HttpStatusCode.OK_200) } }) @@ -179,7 +180,7 @@ describe('Test live', function () { }) it('Should not be able to update a live of another server', async function () { - await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, 403) + await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403) }) it('Should update the live', async function () { @@ -215,8 +216,8 @@ describe('Test live', function () { it('Should have the live deleted', async function () { for (const server of servers) { - await getVideo(server.url, liveVideoUUID, 404) - await getLive(server.url, server.accessToken, liveVideoUUID, 404) + await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) } }) }) @@ -430,8 +431,8 @@ describe('Test live', function () { expect(video.files).to.have.lengthOf(0) const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) - await makeRawRequest(hlsPlaylist.playlistUrl, 200) - await makeRawRequest(hlsPlaylist.segmentsSha256Url, 200) + await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) + await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) @@ -455,8 +456,8 @@ describe('Test live', function () { expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) - await makeRawRequest(file.torrentUrl, 200) - await makeRawRequest(file.fileUrl, 200) + await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) + await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) } } }) -- cgit v1.2.3