1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import { HttpStatusCode } from '@peertube/peertube-models'
import {
cleanupTests,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
waitJobs
} from '@peertube/peertube-server-commands'
describe('Test video sources API validator', function () {
let server: PeerTubeServer = null
let uuid: string
let userToken: string
before(async function () {
this.timeout(120000)
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
userToken = await server.users.generateUserAndToken('user1')
})
describe('When getting latest source', function () {
before(async function () {
const created = await server.videos.quickUpload({ name: 'video' })
uuid = created.uuid
})
it('Should fail without a valid uuid', async function () {
await server.videos.getSource({ id: '4da6fde3-88f7-4d16-b119-108df563d0b0', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should receive 404 when passing a non existing video id', async function () {
await server.videos.getSource({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should not get the source as unauthenticated', async function () {
await server.videos.getSource({ id: uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401, token: null })
})
it('Should not get the source with another user', async function () {
await server.videos.getSource({ id: uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403, token: userToken })
})
it('Should succeed with the correct parameters get the source as another user', async function () {
await server.videos.getSource({ id: uuid })
})
})
describe('When updating source video file', function () {
let userAccessToken: string
let userId: number
let videoId: string
let userVideoId: string
before(async function () {
const res = await server.users.generate('user2')
userAccessToken = res.token
userId = res.userId
const { uuid } = await server.videos.quickUpload({ name: 'video' })
videoId = uuid
await waitJobs([ server ])
})
it('Should fail if not enabled on the instance', async function () {
await server.config.disableFileUpdate()
await server.videos.replaceSourceFile({ videoId, fixture: 'video_short.mp4', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should fail on an unknown video', async function () {
await server.config.enableFileUpdate()
await server.videos.replaceSourceFile({ videoId: 404, fixture: 'video_short.mp4', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should fail with an invalid video', async function () {
await server.config.enableLive({ allowReplay: false })
const { video } = await server.live.quickCreate({ saveReplay: false, permanentLive: true })
await server.videos.replaceSourceFile({
videoId: video.uuid,
fixture: 'video_short.mp4',
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should fail without token', async function () {
await server.videos.replaceSourceFile({
token: null,
videoId,
fixture: 'video_short.mp4',
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail with another user', async function () {
await server.videos.replaceSourceFile({
token: userAccessToken,
videoId,
fixture: 'video_short.mp4',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
it('Should fail with an incorrect input file', async function () {
await server.videos.replaceSourceFile({
fixture: 'video_short_fake.webm',
videoId,
completedExpectedStatus: HttpStatusCode.UNPROCESSABLE_ENTITY_422
})
await server.videos.replaceSourceFile({
fixture: 'video_short.mkv',
videoId,
expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415
})
})
it('Should fail if quota is exceeded', async function () {
this.timeout(60000)
const { uuid } = await server.videos.quickUpload({ name: 'user video' })
userVideoId = uuid
await waitJobs([ server ])
await server.users.update({ userId, videoQuota: 1 })
await server.videos.replaceSourceFile({
token: userAccessToken,
videoId: uuid,
fixture: 'video_short.mp4',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
it('Should succeed with the correct params', async function () {
this.timeout(60000)
await server.users.update({ userId, videoQuota: 1000 * 1000 * 1000 })
await server.videos.replaceSourceFile({ videoId: userVideoId, fixture: 'video_short.mp4' })
})
})
after(async function () {
await cleanupTests([ server ])
})
})
|