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
155
156
157
158
|
/* tslint:disable:no-unused-expression */
import 'mocha'
import * as chai from 'chai'
const expect = chai.expect
import {
ServerInfo,
flushTests,
uploadVideo,
makeFriends,
getVideosList,
wait,
setAccessTokensToServers,
flushAndRunMultipleServers,
killallServers
} from '../utils'
import { VideoPrivacy } from '../../../shared/models/videos/video-privacy.enum'
import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../utils/videos'
import { createUser } from '../utils/users'
import { getUserAccessToken } from '../utils/login'
describe('Test video privacy', function () {
let servers: ServerInfo[] = []
let privateVideoId
let privateVideoUUID
let unlistedVideoUUID
before(async function () {
this.timeout(120000)
// Run servers
servers = await flushAndRunMultipleServers(2)
// Get the access tokens
await setAccessTokensToServers(servers)
// Pod 1 makes friend with pod 2
await makeFriends(servers[0].url, servers[0].accessToken)
})
it('Should upload a private video on pod 1', async function () {
this.timeout(15000)
const attributes = {
privacy: VideoPrivacy.PRIVATE
}
await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
await wait(11000)
})
it('Should not have this private video on pod 2', async function () {
const res = await getVideosList(servers[1].url)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
it('Should list my (private) videos', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
privateVideoId = res.body.data[0].id
privateVideoUUID = res.body.data[0].uuid
})
it('Should not be able to watch this video with non authenticated user', async function () {
await getVideo(servers[0].url, privateVideoUUID, 401)
})
it('Should not be able to watch this private video with another user', async function () {
const user = {
username: 'hello',
password: 'super password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
const token = await getUserAccessToken(servers[0], user)
await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
})
it('Should be able to watch this video with the correct user', async function () {
await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
})
it('Should upload a unlisted video on pod 2', async function () {
this.timeout(30000)
const attributes = {
name: 'unlisted video',
privacy: VideoPrivacy.UNLISTED
}
await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
await wait(22000)
})
it('Should not have this unlisted video listed on pod 1 and 2', async function () {
for (const server of servers) {
const res = await getVideosList(server.url)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
}
})
it('Should list my (unlisted) videos', async function () {
const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
unlistedVideoUUID = res.body.data[0].uuid
})
it('Should be able to get this unlisted video', async function () {
for (const server of servers) {
const res = await getVideo(server.url, unlistedVideoUUID)
expect(res.body.name).to.equal('unlisted video')
}
})
it('Should update the private video to public on pod 1', async function () {
this.timeout(15000)
const attribute = {
name: 'super video public',
privacy: VideoPrivacy.PUBLIC
}
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
await wait(11000)
})
it('Should not have this new unlisted video listed on pod 1 and 2', async function () {
for (const server of servers) {
const res = await getVideosList(server.url)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
expect(res.body.data[0].name).to.equal('super video public')
}
})
after(async function () {
killallServers(servers)
// Keep the logs if the test failed
if (this['ok']) {
await flushTests()
}
})
})
|