]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/client.ts
Handle rejected follows in client
[github/Chocobozzz/PeerTube.git] / server / tests / client.ts
index caf6fb00cdcf71f53690f26c5d2adcb6b1fd3d9f..a8a697f99bebbf91521d65e6731f8701f314ed84 100644 (file)
@@ -3,19 +3,26 @@
 import 'mocha'
 import * as chai from 'chai'
 import { omit } from 'lodash'
-import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
-import { Account, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models'
+import {
+  Account,
+  HTMLServerConfig,
+  HttpStatusCode,
+  ServerConfig,
+  VideoPlaylistCreateResult,
+  VideoPlaylistPrivacy,
+  VideoPrivacy
+} from '@shared/models'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
   makeGetRequest,
   makeHTMLRequest,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   waitJobs
-} from '../../shared/extra-utils'
+} from '../../shared/server-commands'
 
 const expect = chai.expect
 
@@ -25,11 +32,14 @@ function checkIndexTags (html: string, title: string, description: string, css:
   expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
 
   const htmlConfig: HTMLServerConfig = omit(config, 'signup')
-  expect(html).to.contain(`<script type="application/javascript">window.PeerTubeServerConfig = '${JSON.stringify(htmlConfig)}'</script>`)
+  const configObjectString = JSON.stringify(htmlConfig)
+  const configEscapedString = JSON.stringify(configObjectString)
+
+  expect(html).to.contain(`<script type="application/javascript">window.PeerTubeServerConfig = ${configEscapedString}</script>`)
 }
 
 describe('Test a client controllers', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let account: Account
 
   const videoName = 'my super name for server 1'
@@ -46,12 +56,16 @@ 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 () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     await setAccessTokensToServers(servers)
 
@@ -64,7 +78,7 @@ describe('Test a client controllers', function () {
       attributes: { description: channelDescription }
     })
 
-    // Video
+    // Public video
 
     {
       const attributes = { name: videoName, description: videoDescription }
@@ -78,6 +92,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
 
     {
@@ -114,13 +134,13 @@ describe('Test a client controllers', function () {
             url: servers[0].url,
             path: basePath + id,
             accept: 'text/html',
-            statusCodeExpected: HttpStatusCode.OK_200
+            expectedStatus: HttpStatusCode.OK_200
           })
 
           const port = servers[0].port
 
           const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
-            `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].store.video.uuid}" ` +
+            `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].store.video.shortUUID}" ` +
             `title="${servers[0].store.video.name}" />`
 
           expect(res.text).to.contain(expectedLink)
@@ -135,13 +155,13 @@ describe('Test a client controllers', function () {
             url: servers[0].url,
             path: basePath + id,
             accept: 'text/html',
-            statusCodeExpected: HttpStatusCode.OK_200
+            expectedStatus: HttpStatusCode.OK_200
           })
 
           const port = servers[0].port
 
           const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
-            `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.uuid}" ` +
+            `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.shortUUID}" ` +
             `title="${playlistName}" />`
 
           expect(res.text).to.contain(expectedLink)
@@ -153,7 +173,7 @@ describe('Test a client controllers', function () {
   describe('Open Graph', function () {
 
     async function accountPageTest (path: string) {
-      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
       const text = res.text
 
       expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
@@ -163,7 +183,7 @@ describe('Test a client controllers', function () {
     }
 
     async function channelPageTest (path: string) {
-      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
       const text = res.text
 
       expect(text).to.contain(`<meta property="og:title" content="${servers[0].store.channel.displayName}" />`)
@@ -173,23 +193,23 @@ describe('Test a client controllers', function () {
     }
 
     async function watchVideoPageTest (path: string) {
-      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
       const text = res.text
 
       expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`)
       expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
       expect(text).to.contain('<meta property="og:type" content="video" />')
-      expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].store.video.uuid}" />`)
+      expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].store.video.shortUUID}" />`)
     }
 
     async function watchPlaylistPageTest (path: string) {
-      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+      const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
       const text = res.text
 
       expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
       expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
       expect(text).to.contain('<meta property="og:type" content="video" />')
-      expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.uuid}" />`)
+      expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.shortUUID}" />`)
     }
 
     it('Should have valid Open Graph tags on the account page', async function () {
@@ -226,7 +246,7 @@ describe('Test a client controllers', function () {
     describe('Not whitelisted', function () {
 
       async function accountPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary" />')
@@ -236,7 +256,7 @@ describe('Test a client controllers', function () {
       }
 
       async function channelPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary" />')
@@ -246,7 +266,7 @@ describe('Test a client controllers', function () {
       }
 
       async function watchVideoPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
@@ -256,7 +276,7 @@ describe('Test a client controllers', function () {
       }
 
       async function watchPlaylistPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary" />')
@@ -307,7 +327,7 @@ describe('Test a client controllers', function () {
       })
 
       async function accountPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary" />')
@@ -315,7 +335,7 @@ describe('Test a client controllers', function () {
       }
 
       async function channelPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="summary" />')
@@ -323,7 +343,7 @@ describe('Test a client controllers', function () {
       }
 
       async function watchVideoPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="player" />')
@@ -331,7 +351,7 @@ describe('Test a client controllers', function () {
       }
 
       async function watchPlaylistPageTest (path: string) {
-        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 })
+        const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
         const text = res.text
 
         expect(text).to.contain('<meta property="twitter:card" content="player" />')
@@ -446,6 +466,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('<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 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" />')
+      }
+    })
   })
 
   describe('Embed HTML', function () {