misc-endpoints.ts 5.5 KB

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