misc-endpoints.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. import { HttpStatusCode } from '@shared/core-utils'
  16. const expect = chai.expect
  17. describe('Test misc endpoints', function () {
  18. let server: ServerInfo
  19. before(async function () {
  20. this.timeout(120000)
  21. server = await flushAndRunServer(1)
  22. await setAccessTokensToServers([ server ])
  23. })
  24. describe('Test a well known endpoints', function () {
  25. it('Should get security.txt', async function () {
  26. const res = await makeGetRequest({
  27. url: server.url,
  28. path: '/.well-known/security.txt',
  29. statusCodeExpected: HttpStatusCode.OK_200
  30. })
  31. expect(res.text).to.contain('security issue')
  32. })
  33. it('Should get nodeinfo', async function () {
  34. const res = await makeGetRequest({
  35. url: server.url,
  36. path: '/.well-known/nodeinfo',
  37. statusCodeExpected: HttpStatusCode.OK_200
  38. })
  39. expect(res.body.links).to.be.an('array')
  40. expect(res.body.links).to.have.lengthOf(1)
  41. expect(res.body.links[0].rel).to.equal('http://nodeinfo.diaspora.software/ns/schema/2.0')
  42. })
  43. it('Should get dnt policy text', async function () {
  44. const res = await makeGetRequest({
  45. url: server.url,
  46. path: '/.well-known/dnt-policy.txt',
  47. statusCodeExpected: HttpStatusCode.OK_200
  48. })
  49. expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
  50. })
  51. it('Should get dnt policy', async function () {
  52. const res = await makeGetRequest({
  53. url: server.url,
  54. path: '/.well-known/dnt',
  55. statusCodeExpected: HttpStatusCode.OK_200
  56. })
  57. expect(res.body.tracking).to.equal('N')
  58. })
  59. it('Should get change-password location', async function () {
  60. const res = await makeGetRequest({
  61. url: server.url,
  62. path: '/.well-known/change-password',
  63. statusCodeExpected: HttpStatusCode.FOUND_302
  64. })
  65. expect(res.header.location).to.equal('/my-account/settings')
  66. })
  67. it('Should test webfinger', async function () {
  68. const resource = 'acct:peertube@' + server.host
  69. const accountUrl = server.url + '/accounts/peertube'
  70. const res = await makeGetRequest({
  71. url: server.url,
  72. path: '/.well-known/webfinger?resource=' + resource,
  73. statusCodeExpected: HttpStatusCode.OK_200
  74. })
  75. const data = res.body
  76. expect(data.subject).to.equal(resource)
  77. expect(data.aliases).to.contain(accountUrl)
  78. const self = data.links.find(l => l.rel === 'self')
  79. expect(self).to.exist
  80. expect(self.type).to.equal('application/activity+json')
  81. expect(self.href).to.equal(accountUrl)
  82. const remoteInteract = data.links.find(l => l.rel === 'http://ostatus.org/schema/1.0/subscribe')
  83. expect(remoteInteract).to.exist
  84. expect(remoteInteract.template).to.equal(server.url + '/remote-interaction?uri={uri}')
  85. })
  86. })
  87. describe('Test classic static endpoints', function () {
  88. it('Should get robots.txt', async function () {
  89. const res = await makeGetRequest({
  90. url: server.url,
  91. path: '/robots.txt',
  92. statusCodeExpected: HttpStatusCode.OK_200
  93. })
  94. expect(res.text).to.contain('User-agent')
  95. })
  96. it('Should get security.txt', async function () {
  97. await makeGetRequest({
  98. url: server.url,
  99. path: '/security.txt',
  100. statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
  101. })
  102. })
  103. it('Should get nodeinfo', async function () {
  104. const res = await makeGetRequest({
  105. url: server.url,
  106. path: '/nodeinfo/2.0.json',
  107. statusCodeExpected: HttpStatusCode.OK_200
  108. })
  109. expect(res.body.software.name).to.equal('peertube')
  110. expect(res.body.usage.users.activeMonth).to.equal(1)
  111. expect(res.body.usage.users.activeHalfyear).to.equal(1)
  112. })
  113. })
  114. describe('Test bots endpoints', function () {
  115. it('Should get the empty sitemap', async function () {
  116. const res = await makeGetRequest({
  117. url: server.url,
  118. path: '/sitemap.xml',
  119. statusCodeExpected: HttpStatusCode.OK_200
  120. })
  121. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  122. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
  123. })
  124. it('Should get the empty cached sitemap', async function () {
  125. const res = await makeGetRequest({
  126. url: server.url,
  127. path: '/sitemap.xml',
  128. statusCodeExpected: HttpStatusCode.OK_200
  129. })
  130. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  131. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
  132. })
  133. it('Should add videos, channel and accounts and get sitemap', async function () {
  134. this.timeout(35000)
  135. await uploadVideo(server.url, server.accessToken, { name: 'video 1', nsfw: false })
  136. await uploadVideo(server.url, server.accessToken, { name: 'video 2', nsfw: false })
  137. await uploadVideo(server.url, server.accessToken, { name: 'video 3', privacy: VideoPrivacy.PRIVATE })
  138. await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
  139. await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
  140. await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
  141. await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
  142. const res = await makeGetRequest({
  143. url: server.url,
  144. path: '/sitemap.xml?t=1', // avoid using cache
  145. statusCodeExpected: HttpStatusCode.OK_200
  146. })
  147. expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
  148. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/about/instance</loc></url>')
  149. expect(res.text).to.contain('<video:title>video 1</video:title>')
  150. expect(res.text).to.contain('<video:title>video 2</video:title>')
  151. expect(res.text).to.not.contain('<video:title>video 3</video:title>')
  152. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel1</loc></url>')
  153. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/video-channels/channel2</loc></url>')
  154. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user1</loc></url>')
  155. expect(res.text).to.contain('<url><loc>http://localhost:' + server.port + '/accounts/user2</loc></url>')
  156. })
  157. })
  158. after(async function () {
  159. await cleanupTests([ server ])
  160. })
  161. })