misc-endpoints.ts 6.7 KB

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