misc-endpoints.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import {
  5. addVideoChannel,
  6. cleanupTests,
  7. createUser,
  8. flushAndRunServer,
  9. makeGetRequest,
  10. ServerInfo,
  11. setAccessTokensToServers,
  12. uploadVideo
  13. } from '../../shared/extra-utils'
  14. import { VideoPrivacy } from '../../shared/models/videos'
  15. const expect = chai.expect
  16. describe('Test misc endpoints', function () {
  17. let server: ServerInfo
  18. before(async function () {
  19. this.timeout(120000)
  20. server = await flushAndRunServer(1)
  21. await setAccessTokensToServers([ server ])
  22. })
  23. describe('Test a well known endpoints', function () {
  24. it('Should get security.txt', async function () {
  25. const res = await makeGetRequest({
  26. url: server.url,
  27. path: '/.well-known/security.txt',
  28. statusCodeExpected: 200
  29. })
  30. expect(res.text).to.contain('security issue')
  31. })
  32. it('Should get nodeinfo', async function () {
  33. const res = await makeGetRequest({
  34. url: server.url,
  35. path: '/.well-known/nodeinfo',
  36. statusCodeExpected: 200
  37. })
  38. expect(res.body.links).to.be.an('array')
  39. expect(res.body.links).to.have.lengthOf(1)
  40. expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
  41. })
  42. it('Should get dnt policy text', async function () {
  43. const res = await makeGetRequest({
  44. url: server.url,
  45. path: '/.well-known/dnt-policy.txt',
  46. statusCodeExpected: 200
  47. })
  48. expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
  49. })
  50. it('Should get dnt policy', async function () {
  51. const res = await makeGetRequest({
  52. url: server.url,
  53. path: '/.well-known/dnt',
  54. statusCodeExpected: 200
  55. })
  56. expect(res.body.tracking).to.equal('N')
  57. })
  58. it('Should get change-password location', async function () {
  59. const res = await makeGetRequest({
  60. url: server.url,
  61. path: '/.well-known/change-password',
  62. statusCodeExpected: 302
  63. })
  64. expect(res.header.location).to.equal('/my-account/settings')
  65. })
  66. })
  67. describe('Test classic static endpoints', function () {
  68. it('Should get robots.txt', async function () {
  69. const res = await makeGetRequest({
  70. url: server.url,
  71. path: '/robots.txt',
  72. statusCodeExpected: 200
  73. })
  74. expect(res.text).to.contain('User-agent')
  75. })
  76. it('Should get security.txt', async function () {
  77. await makeGetRequest({
  78. url: server.url,
  79. path: '/security.txt',
  80. statusCodeExpected: 301
  81. })
  82. })
  83. it('Should get nodeinfo', async function () {
  84. const res = await makeGetRequest({
  85. url: server.url,
  86. path: '/nodeinfo/2.0.json',
  87. statusCodeExpected: 200
  88. })
  89. expect(res.body.software.name).to.equal('peertube')
  90. })
  91. })
  92. describe('Test bots endpoints', function () {
  93. it('Should get the empty sitemap', async function () {
  94. const res = await makeGetRequest({
  95. url: server.url,
  96. path: '/sitemap.xml',
  97. statusCodeExpected: 200
  98. })
  99. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  100. expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
  101. })
  102. it('Should get the empty cached sitemap', async function () {
  103. const res = await makeGetRequest({
  104. url: server.url,
  105. path: '/sitemap.xml',
  106. statusCodeExpected: 200
  107. })
  108. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  109. expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
  110. })
  111. it('Should add videos, channel and accounts and get sitemap', async function () {
  112. this.timeout(35000)
  113. await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
  114. await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
  115. await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
  116. await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
  117. await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
  118. await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
  119. await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
  120. const res = await makeGetRequest({
  121. url: server.url,
  122. path: '/sitemap.xml?t=1', // avoid using cache
  123. statusCodeExpected: 200
  124. })
  125. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  126. expect(res.text).to.contain('<url><loc>http://localhost:9001/about/instance</loc></url>')
  127. expect(res.text).to.contain('<video:title>video 1</video:title>')
  128. expect(res.text).to.contain('<video:title>video 2</video:title>')
  129. expect(res.text).to.not.contain('<video:title>video 3</video:title>')
  130. expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel1</loc></url>')
  131. expect(res.text).to.contain('<url><loc>http://localhost:9001/video-channels/channel2</loc></url>')
  132. expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user1</loc></url>')
  133. expect(res.text).to.contain('<url><loc>http://localhost:9001/accounts/user2</loc></url>')
  134. })
  135. })
  136. after(async function () {
  137. await cleanupTests([ server ])
  138. })
  139. })