X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fclient.ts;h=e0dae2b5e320894c8b4120b66641d6528fc46939;hb=a8749f7c3b137f433e6944bb99fd721a6f0cfc1e;hp=6255c69612431e731b44687ddab8dd0a9fa74f2c;hpb=c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/client.ts b/server/tests/client.ts index 6255c6961..e0dae2b5e 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -1,31 +1,38 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' -import { Account, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models' +import { expect } from 'chai' +import { omit } from '@shared/core-utils' +import { + Account, + HTMLServerConfig, + HttpStatusCode, + ServerConfig, + VideoPlaylistCreateResult, + VideoPlaylistPrivacy, + VideoPrivacy +} from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeGetRequest, makeHTMLRequest, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs -} from '../../shared/extra-utils' - -const expect = chai.expect +} from '../../shared/server-commands' function checkIndexTags (html: string, title: string, description: string, css: string, config: ServerConfig) { expect(html).to.contain('' + title + '') expect(html).to.contain('') expect(html).to.contain('') - const htmlConfig: HTMLServerConfig = omit(config, 'signup') - expect(html).to.contain(``) + const htmlConfig: HTMLServerConfig = omit(config, [ 'signup' ]) + const configObjectString = JSON.stringify(htmlConfig) + const configEscapedString = JSON.stringify(configObjectString) + + expect(html).to.contain(``) } describe('Test a client controllers', function () { @@ -46,6 +53,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 () { @@ -64,7 +75,7 @@ describe('Test a client controllers', function () { attributes: { description: channelDescription } }) - // Video + // Public video { const attributes = { name: videoName, description: videoDescription } @@ -78,6 +89,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 { @@ -117,11 +134,9 @@ describe('Test a client controllers', function () { expectedStatus: HttpStatusCode.OK_200 }) - const port = servers[0].port - - const expectedLink = '` + const expectedLink = `` expect(res.text).to.contain(expectedLink) } @@ -138,10 +153,8 @@ describe('Test a client controllers', function () { expectedStatus: HttpStatusCode.OK_200 }) - const port = servers[0].port - - const expectedLink = '` expect(res.text).to.contain(expectedLink) @@ -179,7 +192,7 @@ describe('Test a client controllers', function () { expect(text).to.contain(``) expect(text).to.contain(``) expect(text).to.contain('') - expect(text).to.contain(``) + expect(text).to.contain(``) } async function watchPlaylistPageTest (path: string) { @@ -189,7 +202,7 @@ describe('Test a client controllers', function () { expect(text).to.contain(``) expect(text).to.contain(``) expect(text).to.contain('') - expect(text).to.contain(``) + expect(text).to.contain(``) } it('Should have valid Open Graph tags on the account page', async function () { @@ -446,6 +459,70 @@ describe('Test a client controllers', function () { } } }) + + it('Should add noindex meta tag for remote accounts', async function () { + const handle = 'root@' + servers[0].host + const paths = [ '/accounts/', '/a/', '/@' ] + + for (const path of paths) { + { + const { text } = await makeHTMLRequest(servers[1].url, path + handle) + expect(text).to.contain('') + } + + { + const { text } = await makeHTMLRequest(servers[0].url, path + handle) + expect(text).to.not.contain('') + } + } + }) + + 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('') + } + + { + const { text } = await makeHTMLRequest(servers[0].url, path + handle) + expect(text).to.not.contain('') + } + } + }) + + 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('') + } + }) }) describe('Embed HTML', function () {