Skip to content

Commit

Permalink
Disallow unlisted video indexation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Apr 8, 2022
1 parent 1575be6 commit c6d20c8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/lib/client-html.ts
Expand Up @@ -134,6 +134,7 @@ class ClientHtml {
escapedSiteName: escapeHTML(siteName),
escapedTitle: escapeHTML(title),
escapedDescription: escapeHTML(description),
disallowIndexation: video.privacy !== VideoPrivacy.PUBLIC,
image,
embed,
ogType,
Expand Down Expand Up @@ -197,6 +198,7 @@ class ClientHtml {
escapedSiteName: escapeHTML(siteName),
escapedTitle: escapeHTML(title),
escapedDescription: escapeHTML(description),
disallowIndexation: videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC,
embed,
image,
list,
Expand Down
61 changes: 59 additions & 2 deletions server/tests/client.ts
Expand Up @@ -3,7 +3,7 @@
import 'mocha'
import * as chai from 'chai'
import { omit } from 'lodash'
import { Account, HTMLServerConfig, HttpStatusCode, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models'
import { Account, HTMLServerConfig, HttpStatusCode, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
createMultipleServers,
Expand Down Expand Up @@ -48,6 +48,10 @@ describe('Test a client controllers', function () {
const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ]

let videoIds: (string | number)[] = []
let privateVideoId: string
let internalVideoId: string
let unlistedVideoId: string

let playlistIds: (string | number)[] = []

before(async function () {
Expand All @@ -66,7 +70,7 @@ describe('Test a client controllers', function () {
attributes: { description: channelDescription }
})

// Video
// Public video

{
const attributes = { name: videoName, description: videoDescription }
Expand All @@ -80,6 +84,12 @@ describe('Test a client controllers', function () {
videoIds = [ video.id, video.uuid, video.shortUUID ]
}

{
({ uuid: privateVideoId } = await servers[0].videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE }));
({ uuid: unlistedVideoId } = await servers[0].videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED }));
({ uuid: internalVideoId } = await servers[0].videos.quickUpload({ name: 'internal', privacy: VideoPrivacy.INTERNAL }))
}

// Playlist

{
Expand Down Expand Up @@ -466,6 +476,53 @@ describe('Test a client controllers', function () {
}
})

it('Should add noindex meta tag for remote channels', async function () {
const handle = 'root_channel@' + servers[0].host
const paths = [ '/video-channels/', '/c/', '/@' ]

for (const path of paths) {
{
const { text } = await makeHTMLRequest(servers[1].url, path + handle)
expect(text).to.contain('<meta name="robots" content="noindex" />')
}

{
const { text } = await makeHTMLRequest(servers[0].url, path + handle)
expect(text).to.not.contain('<meta name="robots" content="noindex" />')
}
}
})

it('Should not display internal/private video', async function () {
for (const basePath of watchVideoBasePaths) {
for (const id of [ privateVideoId, internalVideoId ]) {
const res = await makeGetRequest({
url: servers[0].url,
path: basePath + id,
accept: 'text/html',
expectedStatus: HttpStatusCode.NOT_FOUND_404
})

expect(res.text).to.not.contain('internal')
expect(res.text).to.not.contain('private')
}
}
})

it('Should add noindex meta tag for unlisted video', async function () {
for (const basePath of watchVideoBasePaths) {
const res = await makeGetRequest({
url: servers[0].url,
path: basePath + unlistedVideoId,
accept: 'text/html',
expectedStatus: HttpStatusCode.OK_200
})

expect(res.text).to.contain('unlisted')
expect(res.text).to.contain('<meta name="robots" content="noindex" />')
}
})

it('Should add noindex meta tag for remote accounts', async function () {
const handle = 'root_channel@' + servers[0].host
const paths = [ '/video-channels/', '/c/', '/@' ]
Expand Down

0 comments on commit c6d20c8

Please sign in to comment.