aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/actor.ts37
-rw-r--r--server/controllers/api/index.ts2
-rw-r--r--server/controllers/client.ts11
-rw-r--r--server/helpers/custom-validators/actor.ts10
-rw-r--r--server/helpers/middlewares/video-channels.ts20
-rw-r--r--server/lib/client-html.ts17
-rw-r--r--server/middlewares/validators/actor.ts59
-rw-r--r--server/middlewares/validators/index.ts1
-rw-r--r--server/tests/api/check-params/actors.ts37
-rw-r--r--server/tests/client.ts154
10 files changed, 299 insertions, 49 deletions
diff --git a/server/controllers/api/actor.ts b/server/controllers/api/actor.ts
new file mode 100644
index 000000000..da7f2eb91
--- /dev/null
+++ b/server/controllers/api/actor.ts
@@ -0,0 +1,37 @@
1import * as express from 'express'
2import { JobQueue } from '../../lib/job-queue'
3import { asyncMiddleware } from '../../middlewares'
4import { actorNameWithHostGetValidator } from '../../middlewares/validators'
5
6const actorRouter = express.Router()
7
8actorRouter.get('/:actorName',
9 asyncMiddleware(actorNameWithHostGetValidator),
10 getActor
11)
12
13// ---------------------------------------------------------------------------
14
15export {
16 actorRouter
17}
18
19// ---------------------------------------------------------------------------
20
21function getActor (req: express.Request, res: express.Response) {
22 let accountOrVideoChannel
23
24 if (res.locals.account) {
25 accountOrVideoChannel = res.locals.account
26 }
27
28 if (res.locals.videoChannel) {
29 accountOrVideoChannel = res.locals.videoChannel
30 }
31
32 if (accountOrVideoChannel.isOutdated()) {
33 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: accountOrVideoChannel.Actor.url } })
34 }
35
36 return res.json(accountOrVideoChannel.toFormattedJSON())
37}
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index 28378654a..9ffcf1337 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -16,6 +16,7 @@ import { pluginRouter } from './plugins'
16import { searchRouter } from './search' 16import { searchRouter } from './search'
17import { serverRouter } from './server' 17import { serverRouter } from './server'
18import { usersRouter } from './users' 18import { usersRouter } from './users'
19import { actorRouter } from './actor'
19import { videoChannelRouter } from './video-channel' 20import { videoChannelRouter } from './video-channel'
20import { videoPlaylistRouter } from './video-playlist' 21import { videoPlaylistRouter } from './video-playlist'
21import { videosRouter } from './videos' 22import { videosRouter } from './videos'
@@ -40,6 +41,7 @@ apiRouter.use('/bulk', bulkRouter)
40apiRouter.use('/oauth-clients', oauthClientsRouter) 41apiRouter.use('/oauth-clients', oauthClientsRouter)
41apiRouter.use('/config', configRouter) 42apiRouter.use('/config', configRouter)
42apiRouter.use('/users', usersRouter) 43apiRouter.use('/users', usersRouter)
44apiRouter.use('/actors', actorRouter)
43apiRouter.use('/accounts', accountsRouter) 45apiRouter.use('/accounts', accountsRouter)
44apiRouter.use('/video-channels', videoChannelRouter) 46apiRouter.use('/video-channels', videoChannelRouter)
45apiRouter.use('/video-playlists', videoPlaylistRouter) 47apiRouter.use('/video-playlists', videoPlaylistRouter)
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 022a17ff4..35e5af9d1 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -21,8 +21,9 @@ const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
21// Do not use a template engine for a so little thing 21// Do not use a template engine for a so little thing
22clientsRouter.use('/videos/watch/playlist/:id', asyncMiddleware(generateWatchPlaylistHtmlPage)) 22clientsRouter.use('/videos/watch/playlist/:id', asyncMiddleware(generateWatchPlaylistHtmlPage))
23clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage)) 23clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage))
24clientsRouter.use('/accounts/:nameWithHost', asyncMiddleware(generateAccountHtmlPage)) 24clientsRouter.use([ '/accounts/:nameWithHost', '/a/:nameWithHost' ], asyncMiddleware(generateAccountHtmlPage))
25clientsRouter.use('/video-channels/:nameWithHost', asyncMiddleware(generateVideoChannelHtmlPage)) 25clientsRouter.use([ '/video-channels/:nameWithHost', '/c/:nameWithHost' ], asyncMiddleware(generateVideoChannelHtmlPage))
26clientsRouter.use('/@:nameWithHost', asyncMiddleware(generateActorHtmlPage))
26 27
27const embedMiddlewares = [ 28const embedMiddlewares = [
28 CONFIG.CSP.ENABLED 29 CONFIG.CSP.ENABLED
@@ -155,6 +156,12 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express.
155 return sendHTML(html, res) 156 return sendHTML(html, res)
156} 157}
157 158
159async function generateActorHtmlPage (req: express.Request, res: express.Response) {
160 const html = await ClientHtml.getActorHTMLPage(req.params.nameWithHost, req, res)
161
162 return sendHTML(html, res)
163}
164
158async function generateManifest (req: express.Request, res: express.Response) { 165async function generateManifest (req: express.Request, res: express.Response) {
159 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') 166 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest')
160 const manifestJson = await readFile(manifestPhysicalPath, 'utf8') 167 const manifestJson = await readFile(manifestPhysicalPath, 'utf8')
diff --git a/server/helpers/custom-validators/actor.ts b/server/helpers/custom-validators/actor.ts
new file mode 100644
index 000000000..ad129e080
--- /dev/null
+++ b/server/helpers/custom-validators/actor.ts
@@ -0,0 +1,10 @@
1import { isAccountNameValid } from './accounts'
2import { isVideoChannelNameValid } from './video-channels'
3
4function isActorNameValid (value: string) {
5 return isAccountNameValid(value) || isVideoChannelNameValid(value)
6}
7
8export {
9 isActorNameValid
10}
diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts
index e6eab65a2..e30ea90b3 100644
--- a/server/helpers/middlewares/video-channels.ts
+++ b/server/helpers/middlewares/video-channels.ts
@@ -3,22 +3,22 @@ import { MChannelBannerAccountDefault } from '@server/types/models'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4import { VideoChannelModel } from '../../models/video/video-channel' 4import { VideoChannelModel } from '../../models/video/video-channel'
5 5
6async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { 6async function doesLocalVideoChannelNameExist (name: string, res: express.Response, sendNotFound = true) {
7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) 7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
8 8
9 return processVideoChannelExist(videoChannel, res) 9 return processVideoChannelExist(videoChannel, res, sendNotFound)
10} 10}
11 11
12async function doesVideoChannelIdExist (id: number, res: express.Response) { 12async function doesVideoChannelIdExist (id: number, res: express.Response, sendNotFound = true) {
13 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) 13 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
14 14
15 return processVideoChannelExist(videoChannel, res) 15 return processVideoChannelExist(videoChannel, res, sendNotFound)
16} 16}
17 17
18async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { 18async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response, sendNotFound = true) {
19 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) 19 const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
20 20
21 return processVideoChannelExist(videoChannel, res) 21 return processVideoChannelExist(videoChannel, res, sendNotFound)
22} 22}
23 23
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
@@ -29,10 +29,12 @@ export {
29 doesVideoChannelNameWithHostExist 29 doesVideoChannelNameWithHostExist
30} 30}
31 31
32function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { 32function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response, sendNotFound = true) {
33 if (!videoChannel) { 33 if (!videoChannel) {
34 res.status(HttpStatusCode.NOT_FOUND_404) 34 if (sendNotFound) {
35 .json({ error: 'Video channel not found' }) 35 res.status(HttpStatusCode.NOT_FOUND_404)
36 .json({ error: 'Video channel not found' })
37 }
36 38
37 return false 39 return false
38 } 40 }
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 4b2968e8b..2f6bce1c7 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -198,11 +198,24 @@ class ClientHtml {
198 } 198 }
199 199
200 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 200 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
201 return this.getAccountOrChannelHTMLPage(() => AccountModel.loadByNameWithHost(nameWithHost), req, res) 201 const accountModelPromise = AccountModel.loadByNameWithHost(nameWithHost)
202 return this.getAccountOrChannelHTMLPage(() => accountModelPromise, req, res)
202 } 203 }
203 204
204 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 205 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
205 return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res) 206 const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
207 return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
208 }
209
210 static async getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
211 const accountModel = await AccountModel.loadByNameWithHost(nameWithHost)
212
213 if (accountModel) {
214 return this.getAccountOrChannelHTMLPage(() => new Promise(resolve => resolve(accountModel)), req, res)
215 } else {
216 const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
217 return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
218 }
206 } 219 }
207 220
208 static async getEmbedHTML () { 221 static async getEmbedHTML () {
diff --git a/server/middlewares/validators/actor.ts b/server/middlewares/validators/actor.ts
new file mode 100644
index 000000000..99b529dd6
--- /dev/null
+++ b/server/middlewares/validators/actor.ts
@@ -0,0 +1,59 @@
1import * as express from 'express'
2import { param } from 'express-validator'
3import { isActorNameValid } from '../../helpers/custom-validators/actor'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import {
7 doesAccountNameWithHostExist,
8 doesLocalAccountNameExist,
9 doesVideoChannelNameWithHostExist,
10 doesLocalVideoChannelNameExist
11} from '../../helpers/middlewares'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13
14const localActorValidator = [
15 param('actorName').custom(isActorNameValid).withMessage('Should have a valid actor name'),
16
17 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking localActorValidator parameters', { parameters: req.params })
19
20 if (areValidationErrors(req, res)) return
21
22 const isAccount = await doesLocalAccountNameExist(req.params.actorName, res, false)
23 const isVideoChannel = await doesLocalVideoChannelNameExist(req.params.actorName, res, false)
24
25 if (!isAccount || !isVideoChannel) {
26 res.status(HttpStatusCode.NOT_FOUND_404)
27 .json({ error: 'Actor not found' })
28 }
29
30 return next()
31 }
32]
33
34const actorNameWithHostGetValidator = [
35 param('actorName').exists().withMessage('Should have an actor name with host'),
36
37 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
38 logger.debug('Checking actorNameWithHostGetValidator parameters', { parameters: req.params })
39
40 if (areValidationErrors(req, res)) return
41
42 const isAccount = await doesAccountNameWithHostExist(req.params.actorName, res, false)
43 const isVideoChannel = await doesVideoChannelNameWithHostExist(req.params.actorName, res, false)
44
45 if (!isAccount && !isVideoChannel) {
46 res.status(HttpStatusCode.NOT_FOUND_404)
47 .json({ error: 'Actor not found' })
48 }
49
50 return next()
51 }
52]
53
54// ---------------------------------------------------------------------------
55
56export {
57 localActorValidator,
58 actorNameWithHostGetValidator
59}
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts
index 24faeea3e..3e1a1e5ce 100644
--- a/server/middlewares/validators/index.ts
+++ b/server/middlewares/validators/index.ts
@@ -1,5 +1,6 @@
1export * from './abuse' 1export * from './abuse'
2export * from './account' 2export * from './account'
3export * from './actor'
3export * from './actor-image' 4export * from './actor-image'
4export * from './blocklist' 5export * from './blocklist'
5export * from './oembed' 6export * from './oembed'
diff --git a/server/tests/api/check-params/actors.ts b/server/tests/api/check-params/actors.ts
new file mode 100644
index 000000000..3a03edc39
--- /dev/null
+++ b/server/tests/api/check-params/actors.ts
@@ -0,0 +1,37 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
6import { getActor } from '../../../../shared/extra-utils/actors/actors'
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8
9describe('Test actors API validators', function () {
10 let server: ServerInfo
11
12 // ---------------------------------------------------------------
13
14 before(async function () {
15 this.timeout(30000)
16
17 server = await flushAndRunServer(1)
18 })
19
20 describe('When getting an actor', function () {
21 it('Should return 404 with a non existing actorName', async function () {
22 await getActor(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404)
23 })
24
25 it('Should return 200 with an existing accountName', async function () {
26 await getActor(server.url, 'root', HttpStatusCode.OK_200)
27 })
28
29 it('Should return 200 with an existing channelName', async function () {
30 await getActor(server.url, 'root_channel', HttpStatusCode.OK_200)
31 })
32 })
33
34 after(async function () {
35 await cleanupTests([ server ])
36 })
37})
diff --git a/server/tests/client.ts b/server/tests/client.ts
index a385edd26..d9a472fdd 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -145,27 +145,51 @@ describe('Test a client controllers', function () {
145 describe('Open Graph', function () { 145 describe('Open Graph', function () {
146 146
147 it('Should have valid Open Graph tags on the account page', async function () { 147 it('Should have valid Open Graph tags on the account page', async function () {
148 const res = await request(servers[0].url) 148 const accountPageTests = (res) => {
149 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
150 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
151 expect(res.text).to.contain('<meta property="og:type" content="website" />')
152 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
153 }
154
155 accountPageTests(await request(servers[0].url)
149 .get('/accounts/' + servers[0].user.username) 156 .get('/accounts/' + servers[0].user.username)
150 .set('Accept', 'text/html') 157 .set('Accept', 'text/html')
151 .expect(HttpStatusCode.OK_200) 158 .expect(HttpStatusCode.OK_200))
159
160 accountPageTests(await request(servers[0].url)
161 .get('/a/' + servers[0].user.username)
162 .set('Accept', 'text/html')
163 .expect(HttpStatusCode.OK_200))
152 164
153 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) 165 accountPageTests(await request(servers[0].url)
154 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) 166 .get('/@' + servers[0].user.username)
155 expect(res.text).to.contain('<meta property="og:type" content="website" />') 167 .set('Accept', 'text/html')
156 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`) 168 .expect(HttpStatusCode.OK_200))
157 }) 169 })
158 170
159 it('Should have valid Open Graph tags on the channel page', async function () { 171 it('Should have valid Open Graph tags on the channel page', async function () {
160 const res = await request(servers[0].url) 172 const channelPageOGtests = (res) => {
173 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
174 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
175 expect(res.text).to.contain('<meta property="og:type" content="website" />')
176 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
177 }
178
179 channelPageOGtests(await request(servers[0].url)
161 .get('/video-channels/' + servers[0].videoChannel.name) 180 .get('/video-channels/' + servers[0].videoChannel.name)
162 .set('Accept', 'text/html') 181 .set('Accept', 'text/html')
163 .expect(HttpStatusCode.OK_200) 182 .expect(HttpStatusCode.OK_200))
183
184 channelPageOGtests(await request(servers[0].url)
185 .get('/c/' + servers[0].videoChannel.name)
186 .set('Accept', 'text/html')
187 .expect(HttpStatusCode.OK_200))
164 188
165 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`) 189 channelPageOGtests(await request(servers[0].url)
166 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) 190 .get('/@' + servers[0].videoChannel.name)
167 expect(res.text).to.contain('<meta property="og:type" content="website" />') 191 .set('Accept', 'text/html')
168 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`) 192 .expect(HttpStatusCode.OK_200))
169 }) 193 })
170 194
171 it('Should have valid Open Graph tags on the watch page with video id', async function () { 195 it('Should have valid Open Graph tags on the watch page with video id', async function () {
@@ -232,27 +256,51 @@ describe('Test a client controllers', function () {
232 }) 256 })
233 257
234 it('Should have valid twitter card on the account page', async function () { 258 it('Should have valid twitter card on the account page', async function () {
235 const res = await request(servers[0].url) 259 const accountPageTests = (res) => {
260 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
261 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
262 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
263 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
264 }
265
266 accountPageTests(await request(servers[0].url)
236 .get('/accounts/' + account.name) 267 .get('/accounts/' + account.name)
237 .set('Accept', 'text/html') 268 .set('Accept', 'text/html')
238 .expect(HttpStatusCode.OK_200) 269 .expect(HttpStatusCode.OK_200))
239 270
240 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 271 accountPageTests(await request(servers[0].url)
241 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 272 .get('/a/' + account.name)
242 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) 273 .set('Accept', 'text/html')
243 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) 274 .expect(HttpStatusCode.OK_200))
275
276 accountPageTests(await request(servers[0].url)
277 .get('/@' + account.name)
278 .set('Accept', 'text/html')
279 .expect(HttpStatusCode.OK_200))
244 }) 280 })
245 281
246 it('Should have valid twitter card on the channel page', async function () { 282 it('Should have valid twitter card on the channel page', async function () {
247 const res = await request(servers[0].url) 283 const channelPageTests = (res) => {
284 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
285 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
286 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
287 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
288 }
289
290 channelPageTests(await request(servers[0].url)
248 .get('/video-channels/' + servers[0].videoChannel.name) 291 .get('/video-channels/' + servers[0].videoChannel.name)
249 .set('Accept', 'text/html') 292 .set('Accept', 'text/html')
250 .expect(HttpStatusCode.OK_200) 293 .expect(HttpStatusCode.OK_200))
251 294
252 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 295 channelPageTests(await request(servers[0].url)
253 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 296 .get('/c/' + servers[0].videoChannel.name)
254 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`) 297 .set('Accept', 'text/html')
255 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) 298 .expect(HttpStatusCode.OK_200))
299
300 channelPageTests(await request(servers[0].url)
301 .get('/@' + servers[0].videoChannel.name)
302 .set('Accept', 'text/html')
303 .expect(HttpStatusCode.OK_200))
256 }) 304 })
257 305
258 it('Should have valid twitter card if Twitter is whitelisted', async function () { 306 it('Should have valid twitter card if Twitter is whitelisted', async function () {
@@ -280,21 +328,45 @@ describe('Test a client controllers', function () {
280 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') 328 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
281 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 329 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
282 330
283 const resAccountRequest = await request(servers[0].url) 331 const accountTests = (res) => {
332 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
333 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
334 }
335
336 accountTests(await request(servers[0].url)
284 .get('/accounts/' + account.name) 337 .get('/accounts/' + account.name)
285 .set('Accept', 'text/html') 338 .set('Accept', 'text/html')
286 .expect(HttpStatusCode.OK_200) 339 .expect(HttpStatusCode.OK_200))
340
341 accountTests(await request(servers[0].url)
342 .get('/a/' + account.name)
343 .set('Accept', 'text/html')
344 .expect(HttpStatusCode.OK_200))
345
346 accountTests(await request(servers[0].url)
347 .get('/@' + account.name)
348 .set('Accept', 'text/html')
349 .expect(HttpStatusCode.OK_200))
287 350
288 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 351 const channelTests = (res) => {
289 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 352 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
353 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
354 }
290 355
291 const resChannelRequest = await request(servers[0].url) 356 channelTests(await request(servers[0].url)
292 .get('/video-channels/' + servers[0].videoChannel.name) 357 .get('/video-channels/' + servers[0].videoChannel.name)
293 .set('Accept', 'text/html') 358 .set('Accept', 'text/html')
294 .expect(HttpStatusCode.OK_200) 359 .expect(HttpStatusCode.OK_200))
360
361 channelTests(await request(servers[0].url)
362 .get('/c/' + servers[0].videoChannel.name)
363 .set('Accept', 'text/html')
364 .expect(HttpStatusCode.OK_200))
295 365
296 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 366 channelTests(await request(servers[0].url)
297 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 367 .get('/@' + servers[0].videoChannel.name)
368 .set('Accept', 'text/html')
369 .expect(HttpStatusCode.OK_200))
298 }) 370 })
299 }) 371 })
300 372
@@ -343,13 +415,23 @@ describe('Test a client controllers', function () {
343 }) 415 })
344 416
345 it('Should use the original account URL for the canonical tag', async function () { 417 it('Should use the original account URL for the canonical tag', async function () {
346 const res = await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host) 418 const accountURLtest = (res) => {
347 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) 419 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`)
420 }
421
422 accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host))
423 accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host))
424 accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host))
348 }) 425 })
349 426
350 it('Should use the original channel URL for the canonical tag', async function () { 427 it('Should use the original channel URL for the canonical tag', async function () {
351 const res = await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host) 428 const channelURLtests = (res) => {
352 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) 429 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`)
430 }
431
432 channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host))
433 channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host))
434 channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host))
353 }) 435 })
354 436
355 it('Should use the original playlist URL for the canonical tag', async function () { 437 it('Should use the original playlist URL for the canonical tag', async function () {